<p>I'm sure this is easy but I can't figure it out:</p>

<p>I have an ASP.NET page with some UpdatePanels on it.  I want the page to <em>completely</em> load with some 'Please wait' text in the UpdatePanels.  Then once the page is <em>completely loaded</em> I want to call a code-behind function to update the UpdatePanel.</p>

<p>Any ideas as to what combination of Javascript and code-behind I need to implement this idea?</p>

<p>SAL</p>

<p>PS: I've tried putting my function call in the Page_Load but then code is run <em>before</em> the page is delivered and, as the function I want to run takes some time, the page simply takes too long to load up.</p>

[{'answer_id': 31980, 'author': 'Tom Carter', 'author_id': 2839, 'author_profile': 'https://Stackoverflow.com/users/2839', 'pm_score': 2, 'selected': False, 'text': '<p>Have a look at <a href="http://msdn.microsoft.com/en-us/library/bb310408.aspx" rel="nofollow noreferrer">ScriptManager.RegisterStartupScript</a></p>\n\n<p>The idea is that you register a script to run on start up (I believe once the page has loaded).  Your script should call a function that causes a post back through your UpdatePanel</p>\n'}, {'answer_id': 32049, 'author': 'Ben Scheirman', 'author_id': 3381, 'author_profile': 'https://Stackoverflow.com/users/3381', 'pm_score': 0, 'selected': False, 'text': "<p>The ScriptManager.RegisterStartupScript allows a script to run on startup inside of an update panel.  if you use the old ClientScript.RegisterStartupScript then the script you render will be outside the bounds of the udpate panel, and thus won't be executed during async page loads.</p>\n"}, {'answer_id': 32069, 'author': 'Daniel Pollard', 'author_id': 2758, 'author_profile': 'https://Stackoverflow.com/users/2758', 'pm_score': 0, 'selected': False, 'text': "<p>Using Tom's approach with the startup script, you can then call:</p>\n\n<blockquote>\n  <p>__doPostBack('UpdatePanelName', '');</p>\n</blockquote>\n"}, {'answer_id': 32784, 'author': 'moza', 'author_id': 3465, 'author_profile': 'https://Stackoverflow.com/users/3465', 'pm_score': 2, 'selected': True, 'text': '<p>Use a timer control that will be fired after a certain number of milliseconds (for page to load). In the timer tick event refresh the update panel.</p>\n'}, {'answer_id': 33161, 'author': 'SAL', 'author_id': 3099, 'author_profile': 'https://Stackoverflow.com/users/3099', 'pm_score': 3, 'selected': False, 'text': '<p>I fiddled around with the ScriptManager suggestions - which I reckon I would have eventually got working but it seems to me that the Timer idea is easier to implement and not really(!) that much of a hack?!</p>\n\n<p>Here\'s how I got my panel updated <em>after</em> the initial page render was complete...</p>\n\n<p>default.aspx</p>\n\n<pre><code>    &lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AJAXPostLoadCall._Default" %&gt;\n\n&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;\n\n&lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;\n&lt;head runat="server"&gt;\n    &lt;title&gt;Untitled Page&lt;/title&gt;\n&lt;/head&gt;\n&lt;body&gt;\n    &lt;form id="form1" runat="server"&gt;\n    &lt;h2&gt;And now for a magic trick...&lt;/h2&gt;\n    &lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True"&gt;\n        &lt;/asp:ScriptManager&gt;\n        &lt;div&gt;\n            &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;\n                &lt;ContentTemplate&gt;\n                    &lt;asp:Timer ID="Timer1" runat="server" Interval="2000" ontick="Timer1_Tick" /&gt;\n                    &lt;asp:Label ID="Label1" runat="server"&gt;Something magic is about to happen...&lt;/asp:Label&gt;\n                &lt;/ContentTemplate&gt;\n            &lt;/asp:UpdatePanel&gt;\n\n        &lt;/div&gt;\n    &lt;/form&gt;\n&lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n\n<p>and the code behind default.aspx.cs reads</p>\n\n<pre><code>using System;\nusing System.Collections;\nusing System.Configuration;\nusing System.Data;\nusing System.Linq;\nusing System.Web;\nusing System.Web.Security;\nusing System.Web.UI;\nusing System.Web.UI.HtmlControls;\nusing System.Web.UI.WebControls;\nusing System.Web.UI.WebControls.WebParts;\nusing System.Xml.Linq;\n\nnamespace AJAXPostLoadCall\n{\n    public partial class _Default : System.Web.UI.Page\n    {\n\n        protected void Page_Load(object sender, EventArgs e)\n        {\n        }\n\n        public void DoMagic()\n        {\n            Label1.Text = "Abracadabra";\n        }\n\n        protected void Timer1_Tick(object sender, EventArgs e)\n        {\n            // Do the magic, then disable the timer\n            DoMagic();\n            Timer1.Enabled = false;\n        }\n\n    }\n}\n</code></pre>\n\n<p>So, the page loads up and the Timer (contained within the UpdatePanel) fires 2 secs after the page has loaded up (I think - I\'m not sure when the Timer actually starts?).  The label text is rewritten and then the Timer is disabled to stop any more updates.</p>\n\n<p>Simple enough - but can you purists out there tell me if this is a Horrible Hack?</p>\n'}, {'answer_id': 881498, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>A thumbs-up and thanks to SAL and the rest of you guys.\nThis solved a big issue I had, my procedure was taking up to a minute for the page to finally render and display.</p>\n\n<p>Thanks!</p>\n'}, {'answer_id': 881947, 'author': 'erikkallen', 'author_id': 47161, 'author_profile': 'https://Stackoverflow.com/users/47161', 'pm_score': 1, 'selected': False, 'text': "<p>Doing things like this with UpdatePanels rather than something easily understandable WILL bite you, it's just a matter of when.</p>\n"}, {'answer_id': 1079187, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>From the very first question on this post, I think what the user is looking for is a message to be displayed to the user while the update panel loads. Just put an UpdateProgress control like the one below on your page just above your UpdatePanel control, and feel free to trigger an event in your UpdatePanel, put your backend code as usual, and whatever is contained inside the UpdateProgress control will load up while your UpdatePanel content is being processed in the backend.</p>\n\n<pre><code>&lt;asp:UpdateProgress AssociatedUpdatePanelID="UpdatePanel1" ID="UpdateProgress1" runat="server"&gt;\n  &lt;ProgressTemplate&gt;\n    &lt;div class="mystyleclass"&gt;\n      Please Wait...\n    &lt;/div&gt;\n  &lt;/ProgressTemplate&gt;\n&lt;/asp:UpdateProgress&gt;\n</code></pre>\n\n<p>There is no need for any messy manual javascript stuff.</p>\n'}]
['https://Stackoverflow.com/questions/31935', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3099/']