
Using Multiple UpdateProgress Controls
One UpdateProgress control on the page can show a progress message for all UpdatePanel controls on the page. Asynchronous postbacks originating inside an UpdatePanel control cause the UpdateProgress control to display its message. Postbacks from controls that are triggers for the panel also display the message.
You can associate the UpdateProgress control with a single UpdatePanel control by setting the progress control's AssociatedUpdatePanelID property. In that case, the UpdateProgress control displays a message only when a postback originates inside the associated UpdatePanel control.
In the next procedure, two UpdateProgress controls are added to a page, each associated with a different UpdatePanel control.
To use multiple UpdateProgress controls on a page
Create a new page and switch to Design view.
In the AJAX Extensions tab of the toolbox, double-click the ScriptManager control to add it to the page.
Double-click the UpdatePanel control two times to add two instances of the control to the page.
.png)
In each UpdatePanel control, add a Label control and a Button control.
Set the Text property of both Label controls to Panel Initially Rendered.
.png)
Double-click each Button control to add a handler for each button's Click event.
Add the following code to each Click handler, which artificially creates a three-second delay and then displays the current time.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
' Introducing delay for demonstration.
System.Threading.Thread.Sleep(3000)
Label1.Text = "Page refreshed at " & _
DateTime.Now.ToString()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
' Introducing delay for demonstration.
System.Threading.Thread.Sleep(3000)
Label1.Text = "Page refreshed at " & _
DateTime.Now.ToString()
End Sub
protected void Button1_Click(object sender, EventArgs e)
{
// Introducing delay for demonstration.
System.Threading.Thread.Sleep(3000);
Label1.Text = "Page refreshed at " +
DateTime.Now.ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
// Introducing delay for demonstration.
System.Threading.Thread.Sleep(3000);
Label2.Text = "Page refreshed at " +
DateTime.Now.ToString();
}
Switch to Design view.
Click inside the first UpdatePanel control and add an UpdateProgress control.
Inside the UpdateProgress control, add the text Panel1 Updating.
This sets the ProgressTemplate property.
Select the UpdateProgress control, and in the Properties window, set the AssociatedUpdatePanelID property to UpdatePanel1.
.png)
Click inside the second UpdatePanel control and add a second UpdateProgress control.
Set the text of the UpdateProgress control to Panel2 Updating and set its AssociatedUpdatePanelID property to UpdatePanel2.
.png)
Save your changes, and then press CTRL+F5 to view the page in a browser.
Click the button in the first panel.
After a short delay, the progress message associated with the first panel is displayed. The other UpdateProgress control is not displayed.
Click the button in the second panel.
The progress message associated with the second panel is displayed.
The example is styled to better show the region of the page that the UpdatePanel represents.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
' Introducing delay for demonstration.
System.Threading.Thread.Sleep(3000)
Label1.Text = "Page refreshed at " & _
DateTime.Now.ToString()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
' Introducing delay for demonstration.
System.Threading.Thread.Sleep(3000)
Label1.Text = "Page refreshed at " & _
DateTime.Now.ToString()
End Sub
</script>
<html >
<head id="Head1" runat="server">
<title>UpdateProgress Tutorial</title>
<style type="text/css">
#UpdatePanel1, #UpdatePanel2 {
width:300px; height:100px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel1</legend>
<asp:Label ID="Label1" runat="server" Text="Panel initially rendered."></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
Panel1 updating...
</ProgressTemplate>
</asp:UpdateProgress>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel2</legend>
<asp:Label ID="Label2" runat="server" Text="Panel initially rendered."></asp:Label>
<br />
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
<asp:UpdateProgress ID="UpdateProgress2" runat="server" AssociatedUpdatePanelID="UpdatePanel2">
<ProgressTemplate>
Panel2 updating....
</ProgressTemplate>
</asp:UpdateProgress>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
// Introducing delay for demonstration.
System.Threading.Thread.Sleep(3000);
Label1.Text = "Page refreshed at " +
DateTime.Now.ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
// Introducing delay for demonstration.
System.Threading.Thread.Sleep(3000);
Label2.Text = "Page refreshed at " +
DateTime.Now.ToString();
}
</script>
<html >
<head id="Head1" runat="server">
<title>UpdateProgress Tutorial</title>
<style type="text/css">
#UpdatePanel1, #UpdatePanel2 {
width:300px; height:100px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel1</legend>
<asp:Label ID="Label1" runat="server" Text="Panel initially rendered."></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
Panel1 updating...
</ProgressTemplate>
</asp:UpdateProgress>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel2</legend>
<asp:Label ID="Label2" runat="server" Text="Panel initially rendered."></asp:Label>
<br />
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
<asp:UpdateProgress ID="UpdateProgress2" runat="server" AssociatedUpdatePanelID="UpdatePanel2">
<ProgressTemplate>
Panel2 updating....
</ProgressTemplate>
</asp:UpdateProgress>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>