ASP.NET AJAX: restarting UpdatePanel after page load

I am sure this is easy, but I can not understand:

I have an ASP.NET page with some updates on it. I want the page to fully load with the text "Wait" in UpdatePanels. Then, when the page is fully loaded, I want to call the code function to update UpdatePanel.

Any ideas on which combination of Javascript and code I need to implement this idea?

Sal

PS: I tried to put my function call in Page_Load, but then the code runs before the page is delivered, and since the function I want to run takes some time, the page just loads too long.

+7
javascript asp.net-ajax
source share
8 answers

Use a timer that will start after a certain number of milliseconds (to load the page). In the timer event, refresh the update panel.

+1
source share

I was busy with ScriptManager suggestions, which, in my opinion, I would eventually work, but it seems to me that the idea of ​​the Timer is easier to implement and not really (!), That most of the hack ?!

This is how I updated my dashboard after completing the initial page rendering ...

default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AJAXPostLoadCall._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <h2>And now for a magic trick...</h2> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True"> </asp:ScriptManager> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Timer ID="Timer1" runat="server" Interval="2000" ontick="Timer1_Tick" /> <asp:Label ID="Label1" runat="server">Something magic is about to happen...</asp:Label> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html> 

and the default code default.aspx.cs reads

 using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; namespace AJAXPostLoadCall { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } public void DoMagic() { Label1.Text = "Abracadabra"; } protected void Timer1_Tick(object sender, EventArgs e) { // Do the magic, then disable the timer DoMagic(); Timer1.Enabled = false; } } } 

Thus, the page loads and the timer (contained in the UpdatePanel) fires 2 seconds after the page loads (I think I'm not sure when the timer actually starts?). The label text is overwritten, and then the timer is turned off to stop all updates.

Simple enough - but can you, purists, tell me if this is a terrible hack?

+8
source share

Take a look at ScriptManager.RegisterStartupScript

The idea is that you register a script to run at startup (I believe that after the page loads). Your script should call a function that returns the message back through the UpdatePanel

+2
source share

Performing such actions with UpdatePanels rather than something that is easy to understand will bite you, it's just a matter of when.

+1
source share

From the very first question on this post, I think the user is looking for a message that will be displayed to the user during the download of the update panel. Just put the UpdateProgress control, like the one below on your page just above your UpdatePanel control, and feel free to fire the event in your UpdatePanel, put your internal code as usual, and everything inside the UpdateProgress control will load while your UpdatePanel content is being processed in the backend.

 <asp:UpdateProgress AssociatedUpdatePanelID="UpdatePanel1" ID="UpdateProgress1" runat="server"> <ProgressTemplate> <div class="mystyleclass"> Please Wait... </div> </ProgressTemplate> </asp:UpdateProgress> 

No messy javascript files needed.

+1
source share

ScriptManager.RegisterStartupScript allows you to run a script when launched inside the update panel. if you use the old ClientScript.RegisterStartupScript, then the script you created will be located outside the udpate panel and, therefore, will not be executed when the asynchronous page loads.

0
source share

Using the Tom approach with running the script, you can call:

__ doPostBack ('UpdatePanelName', '');

0
source share

Thumb up and thanks SAL, and the rest of you guys. This solved the big question that I had, my procedure took a minute while the page was finally displayed and displayed.

Thanks!

0
source share

All Articles