Click here to Skip to main content
6,630,901 members and growing! (20,016 online)
Email Password   helpLost your password?
Web Development » Ajax and Atlas » Controls     Beginner License: The Code Project Open License (CPOL)

The UpdateProgress Control of ASP.NET AJAX Extensions

By Shiju Varghese

An introduction to the UpdateProgress control and how to use the UpdateProgress control and UpdatePanel with triggers.
C#, Javascript, XML, HTML, Windows, .NET 2.0, ASP.NET, Visual Studio, Ajax, Dev
Posted:1 Apr 2007
Updated:11 Apr 2007
Views:101,155
Bookmarked:48 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
13 votes for this article.
Popularity: 4.61 Rating: 4.14 out of 5

1
1 vote, 7.7%
2
2 votes, 15.4%
3
2 votes, 15.4%
4
8 votes, 61.5%
5

Introduction

One of the excellent features of ASP.NET AJAX Extensions 1.0 is the UpdatePanel control. The UpdatePanel control enables partial-page rendering in an ASP.NET Web page asynchronously. The contents of the UpdatePanel control will automatically update when a postback event is invoked. This control does work the same as the MagicAjax.net panel control. The UpdateProgress control is very useful when working with the UpdatePanel control. With an UpdateProgress control, you can show the status during the partial-page rendering of an UpdatePanel.

Below is the sample code that uses the UpdateProgress control associated with an UpdatePanel control.

<asp:ScriptManager ID="ScriptManager1" runat="server">
 </asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
 <ContentTemplate>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <asp:Button ID="Button1" runat="server" 
                OnClick="Button1_Click" Text="Button" />
  </ContentTemplate>
 </asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" 
     AssociatedUpdatePanelID="UpdatePanel1" runat="server">
<ProgressTemplate>Update in Progress……..  </ProgressTemplate> 
</asp:UpdateProgress>

In the <ProgressTemplate>, you can use an image instead of static text. Check the code below:

<ProgressTemplate>
 <img src="animatedprogress.jpg" />
</ProgressTemplate>

How to work the UpdateProgress control and the UpdatePanel with triggers

In the above code, the contents inside the <ContentTemplate> will asynchronously update when the Click event of the Button is invoked. While starting an asynchronous postback, the UpdateProgress control will work. The contents inside the <ProgressTemplate> tag will show during the partial-page rendering of an UpdatePanel. The AssociatedUpdatePanelID is the UpdatePanel control you associated with an UpdateProgress control. In the above example, the Button control displays inside the UpdatePanel so that partial-page rendering will automatically be done when the Click event is invoked. But in many cases, you have to update the contents of the UpdatePanel while postback of the controls happens outside the UpdatePanel. In that case, you can use AsyncPostBackTrigger in the <Triggers> section of the UpdatePanel.

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers> 
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click"/>
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" 
     AssociatedUpdatePanelID="UpdatePanel1" runat="server">
<ProgressTemplate>
Update in Progress……..
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Button ID="Button1" runat="server" 
     OnClick="Button1_Click" Text="Button" />

In the above example, the Button control sits outside the UpdatePanel control. If you want to update the contents of the UpdatePanel control when the Click event occurs, you can use the following markup:

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Event"/>
</Triggers>

But in the above scenario, the UpdateProgress control will not work because the asynchronous postback results from a control (in the above example, the Button control) that is not inside the UpdatePanel. In that case, you can display an UpdateProgress control programmatically using JavaScript. Add the following JavaScript code in the script block:

var prm = Sys.WebForms.PageRequestManager.getInstance(); 
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
var postBackElement;
function InitializeRequest(sender, args)
{ 
  if (prm.get_isInAsyncPostBack())
  args.set_cancel(true);
  postBackElement = args.get_postBackElement(); 

  if (postBackElement.id == 'Button1')
  $get('UpdateProgress1').style.display = 'block';
}
function EndRequest(sender, args)
{ 
  if (postBackElement.id == 'Button1')
  $get('UpdateProgress1').style.display = 'none'; 
}

In the above code, I have used the initializeRequest event and the endRequest event of the Sys.WebForms.PageRequestManager class. The initializeRequest event will invoke during the initialization of the asynchronous postback, and the endRequest event will invoke after an asynchronous postback is finished and the control has been returned to the browser.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Shiju Varghese


Member
Shiju Varghese is a Software Developer and Architect specialising with Microsoft technologies.He has been involved with .NET since its first beta version and also a Microsoft Certified Application Developer for .NET. His technical skills are .NET 3.5, C# 3.0, ASP.net 3.5, WCF, WPF and Sql Server. He is currently working with Ernst & Young, Trivandrum, India.

You can check out his blog from http://weblogs.asp.net/shijuvarghese
You can contact him via shiju.varghese@live.com.
Occupation: Software Developer (Senior)
Company: Ernst & Young
Location: India India

Other popular Ajax and Atlas articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 20 of 20 (Total in Forum: 20) (Refresh)FirstPrevNext
GeneralShow message Pinmemberperspolis20:09 1 Jun '09  
GeneralHow to Update the ProgressTemplate Text while page is running PinmemberDumbur20:43 5 Mar '09  
GeneralApplying font style to progress bar Pinmembermeeram3950:48 12 Jan '09  
GeneralThanks! Pinmemberjftejadal12:46 12 Nov '08  
GeneralAlso got rid of the UpdateProgress Control Pinmemberjalvarezca9:26 11 Nov '08  
GeneralAnother way to do same thing Pinmemberdbbtvlzfpz4:11 24 Oct '08  
General[Message Removed] Pinmembernompel8:39 1 Oct '08  
Generalwhenever pageloading alert will come and page should be disable. Pinmemberkathyani3:04 17 Jul '08  
GeneralRe: whenever pageloading alert will come and page should be disable. PinmemberJasonC726:20 13 Oct '08  
GeneralA way around this PinmemberLiam Wheldon12:06 14 Jun '08  
GeneralGracias PinmemberJarpi6:06 28 Apr '08  
GeneralJust what I needed Pinmemberdaokfella11:24 9 Apr '08  
GeneralUpdateProgress with Content and Master Pages Pinmemberremy11:53 15 Nov '07  
GeneralRe: UpdateProgress with Content and Master Pages Pinmemberratul_ctg20:38 16 Feb '09  
GeneralThanks!!! Pinmember_Thurein_17:19 12 Nov '07  
GeneralRe: Thanks!!! Pinmemberrahu_1227:47 20 Aug '09  
GeneralGetting error PinmemberAnilesh5:59 30 May '07  
GeneralRe: Getting error Pinmemberwebdevr5:51 21 Jun '07  
GeneralWhere to place the JavaScript [modified] Pinmemberjakeschirm12:07 9 May '07  
GeneralRe: Where to place the JavaScript Pinmemberwebdevr5:58 21 Jun '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 11 Apr 2007
Editor: Smitha Vijayan
Copyright 2007 by Shiju Varghese
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project