UpdatePanel control enable partial page rendering in ASP.Net. using UpdateProgress control enable status when Updating UpdatePanel. UpdateProgress have ProgressTemplate, When updates is happen UpdateProgress show the content in ProgressTemplate.
<asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID="UpdatePanel1" runat="server"> <ProgressTemplate> <div style="color:Red;font-size:xx-large;">Please wait ......</div> </ProgressTemplate> </asp:UpdateProgress>
AssociatedUpdatePanelID is enable which update is shown update process. Here i am displaying time in label control. When user click update button status is shown in UpdateProgress control
protected void UpdateTime_Click(object sender, EventArgs e)
{
//sleeps for 2 seconds
System.Threading.Thread.Sleep(2000);
lblDate.Text = DateTime.Now.ToString();
}
Full Source Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!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></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID="UpdatePanel1" runat="server"> <ProgressTemplate> <div style="color:Red;font-size:xx-large;">Please wait ......</div> </ProgressTemplate> </asp:UpdateProgress> <asp:UpdatePanel runat="Server" ID="UpdatePanel1" UpdateMode="Conditional"> <ContentTemplate> <asp:Label ID="lblDate" runat="server"></asp:Label> <asp:Button ID="UpdateTime" runat="server" onclick="UpdateTime_Click" Text="Update" /> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html>Server side code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblDate.Text = DateTime.Now.ToString();
}
}
protected void UpdateTime_Click(object sender, EventArgs e)
{
//sleeps for 2 seconds
System.Threading.Thread.Sleep(2000);
lblDate.Text = DateTime.Now.ToString();
}
}
Output
Download Source

