Gmail like always visible Progress Indicator using ASP.Net, AJAX UpdateProgress & AlwaysVisibleControlExtender

In complex web applications showing progress indicator while postbacks are in progress, enhances the user experience by providing feedback about the process happening in the background.

Gmail has this “loading ….” Progress indicator while they are fetching the mail from their servers or any lenghty server calls are being made. Achieving something similar is a piece of cake using ASP.Net AJAX by using UpdatePanel, UpdateProgress & AlwaysVisibleControlExtender.

Set AlwaysVisibleControlExtender’s target control id to the “UpdateProgress” control’s ID & add the progress indicator image inside the “ProgressTemplate” of the “UpdatProgress” control.




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>GMail like always visible progress indicatortitle>
    <style type="text/css">
        .body
        {
            background-color: #999;
        }
    style>
head>
<body>
    <center>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        asp:ScriptManager>
        <cc1:AlwaysVisibleControlExtender runat="server" ID="awce" TargetControlID="updateProgress"
            VerticalSide="Top" VerticalOffset="10" HorizontalSide="Center">
        cc1:AlwaysVisibleControlExtender>
        <div style="height: 1000px; border: solid 1px red; background: #00728f;">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <br />
                    <br />
                    <br />
                    <asp:Button ID="Button1" runat="server" Text="Update!" OnClick="Button1_Click" />
                ContentTemplate>
            asp:UpdatePanel>
        div>
        <asp:UpdateProgress runat="server" ID="updateProgress">
            <ProgressTemplate>
                <div id="progressIndicator" style="border: solid 1px #FFF;" runat="server">
                    <img src="gfx/ajax-loader.gif" />
                div>
            ProgressTemplate>
        asp:UpdateProgress>
        form>
    center>
body>
html>
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;
using System.Data.SqlClient;
using System.Threading;

public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Thread.Sleep(10000);
    }
}

Comments

Popular posts from this blog

WPF How to Dispose ViewModel when the associated UserControl (Not Window) closes?

C# How to unit test Dispatcher

WPF: How to Deep Copy WPF object (e.g. UIElement) ?