Friday, October 01, 2010

How to show the progress of a request


This approach is suitable if your request delays due to content downloading, such as images and other body content. Page response time cannot be predicted. For the first page load it gets all the data while subsequent responses get cached data. So if you provide constant delay on progress users may lose the joy or browser cache and improved performance by modern browsers. On the other hand, if your request gets delayed by execution of the page such as database calls, web service calls etc, you may consider handing long running operations.
  1. Simple example - only strat message and end message
  2. Detailed example - including progress bar and step processing results
Back this article. Couple of points understand:
  • At the end of the page, we have the JavaScript to hide the progress bar.
  • However, if you hide the progress bar immediately, user still notify a blank space.
  • So if you certain that page loading take a while about 2-4 seconds it is better you delay the hide statement at the end of the page.
setTimeout("document.getElementById('progress').style.display = 'none'", 5000);
<%@ Page Language="C#" %>
<head runat="server">
    <style type="text/css">
        div.DialogueBackground div.Dialogue 
            border:solid 10px #555; 
        div.DialogueBackground div.Dialogue  p { padding:20px 10px; }
    <script runat="server">
        protected override void OnLoad(EventArgs e)
            /// one MB size of request and resposne. 
            for (int i = 0; i < 1000; i++)
                Image img = new Image() { ImageUrl = "SomeImage" + i + ".png" };
    <form id="form1" runat="server">
        <div class="DialogueBackground" id="progress">
            <div class="Dialogue">
                <p>Please wait...</p>
                <img src="::root/::images/Progress.gif" alt="Processing" />
        <asp:Button runat="server" ID="btnSave" Text="Save" 
            OnClientClick="javascript:document.getElementById('progress').style.display = 'block'" />
        <asp:PlaceHolder runat="server" ID="phContent" />
    <script language="javascript" type="text/javascript">
        setTimeout("document.getElementById('progress').style.display = 'none'", 5000);

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...