title: ASP.NET - Display Message While Page Is Loading
body: <p>I have a page that performs a long-running task (10 to 15 seconds) in the page_load method.</p>
  
  <p>I have client-side javascript code that will display a decent "page loading" animated gif to the user.</p>
  
  <p>I am able to invoke the JavaScript method from the code-behind, to display the "page loading" animated gif, however, the long-running task is hanging up the UI such that the animated gif doesn't actually display until after the long-running task is complete, which is the exact opposite of what I want.</p>
  
  <p>To test this out, in my page_load method I make a call to the JavaScript method to display the animated gif.  Then, I use Thread.Sleep(10000).  What happens is that the animated gif doesn't display until after Thread.Sleep is complete.</p>
  
  <p>Obviously I am doing something incorrect.</p>
  
  <p>Any advice would be appreciated.</p>
  
  <p>Thanks.</p>
  
  <p>Chris</p>
  
  <p>Below is an example of the code-behind:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
          ClientScript.RegisterStartupScript
                (GetType(), "Javascript", "javascript: ShowWaitIndicator(); ", true);
  
          Response.Flush();
  
          Thread.Sleep(10000);
      }
  </code></pre>