Click here to Skip to main content
15,170,343 members
Articles / Web Development / HTML
Posted 6 Oct 2006


156 bookmarked

Atlas: ModalUpdateProgress - An UpdateProgress Control in Modal Popup Style

Rate me:
Please Sign up or sign in to vote.
4.65/5 (42 votes)
26 Jun 20073 min read
A progress indicator control that works in a modal popup style.

Sample Image - ModalUpdateProgress.jpg


ASP.NET AJAX has a cool UpdateProgress control that provides a visual indicator while one or more of the UpdatePanel controls are being updated. However, it will be much more useful if all other elements on the page could be disabled when the UpdateProgress is shown. This led me to build the ModalUpdateProgress control in which the UpdateProgress will act as a modal popup.

How UpdateProgress Control Works

If you open up System.Web.Extensions.dll using reflector, you will be able to look up how UpdateProgress control works. Simply put, it implements IScriptControl's two methods GetScriptDescriptors() and GetScriptReferences(). According to the AJAX documentation, GetScriptDescriptors() returns a list of components, behaviors, and client controls required for the UpdateProgress control's client functionality; and GetScriptReferences() returns a list of client script library dependencies for the UpdateProgress control. In GetScriptDescriptors(), the UpdateProgress control registers a ScriptControlDescriptor with type name Sys.UI._UpdateProgress, which is a class available in MicrosoftAjaxWebForms.js (MicrosoftAjaxWebForms.js is one of the ASP.NET AJAX client script libraries, embedded in the System.Web.Extensions.dll). It is pretty straightforward to understand the logic in Sys.UI._UpdateProgress by looking into the debug version of MicrosoftAjaxWebForms.js.

Building the ModalUpdateProgress Control

First, we derive ModalUpdateProgress from UpdateProgress so that we can reuse its existing properties and interface. Then we need to override the two methods GetScriptDescriptors() and GetScriptReferences(), and implement the client-side script component. We will name the client script component as Sys.UI._ModalUpdateProgress, which in turn will be a sub class of Sys.UI._UpdateProgress.

The following is the detail implementation of GetScriptDescriptors() and GetScriptReferences():

/// <span class="code-SummaryComment"><summary></span>
/// Gets the script descriptors.
/// <span class="code-SummaryComment"></summary></span>
/// <span class="code-SummaryComment"><returns>A list of components, behaviors, and </span>
/// client controls required
/// for the ModalUpdateProgress control's client functionality
/// <span class="code-SummaryComment"></returns></span>
protected override IEnumerable<ScriptDescriptor> GetScriptDescriptors()
  if (((this.Page != null) && this.ScriptManager
      .SupportsPartialRendering) && this.Visible)
    ScriptControlDescriptor desc = new ScriptControlDescriptor(
       "Sys.UI._ModalUpdateProgress", this.ClientID);
    string updatePanelClientID = null;
    if (!string.IsNullOrEmpty(this.AssociatedUpdatePanelID))
        UpdatePanel panel = this.NamingContainer.FindControl(this
            .AssociatedUpdatePanelID) as UpdatePanel;
        if (panel == null)
            panel = this.Page.FindControl(this
               .AssociatedUpdatePanelID) as UpdatePanel;

        if (panel == null)
            throw new InvalidOperationException(string.Format(
                CultureInfo.InvariantCulture, "No UpdatePanel 
                found for AssociatedUpdatePanelID '{0}'.",
                new object[] { this.AssociatedUpdatePanelID }));

        updatePanelClientID = panel.ClientID;

    string backgroundCssClass = null;
    string cancelControlID = null;
    if (!string.IsNullOrEmpty(this._backgroundCssClass))
        backgroundCssClass = this._backgroundCssClass;

    if (!string.IsNullOrEmpty(this._cancelControlID))
        cancelControlID = this._cancelControlID;

    desc.AddProperty("associatedUpdatePanelId", updatePanelClientID);
    desc.AddProperty("dynamicLayout", this.DynamicLayout);
    desc.AddProperty("displayAfter", this.DisplayAfter);
    desc.AddProperty("backgroundCssClass", backgroundCssClass);
    desc.AddProperty("cancelControlID", cancelControlID);
    yield return desc;

/// <span class="code-SummaryComment"><summary></span>
/// Gets the script references.
/// <span class="code-SummaryComment"></summary></span>
/// <span class="code-SummaryComment"><returns>A list of client script library dependencies for the control.</span>
/// <span class="code-SummaryComment"></returns></span>
protected override IEnumerable<ScriptReference> GetScriptReferences()
    yield return new ScriptReference("AjaxControls.ModalUpdateProgress.js", "

Both methods return IEnumerable's that will be later handled by ScriptManager.

To implement the client-side script component Sys.UI._ModalUpdateProgress, we can borrow scripts from the ModalPopup control available in the AJAX Control Toolkit. In order to get the script to work for the control, I have to make some minor tweakings, which won't be discussed here. For those who are interested, please look into the ModalUpdateProgress.js in the source for detailed implementation.

How to Use

Just like the UpdateProgress control, you can use the ProgressTemplate property to customize your progress indicator in ModalUpdateProgress.

The ModalUpdateProgress control has an extra property BackgroundCssClass which is used to set the CSS class for the background when the control is displayed. In addition, the ProgressTemplate can include a button that the user can click on to cancel the update in progress. In order for the cancel button to work, you should specify the CancelControlID property using the button ID in the ProgressTemplate.

The following shows an example of adding the ModalUpdateProgress to the page:

<asp:ModalUpdateProgress ID="ModalUpdateProgress1" DisplayAfter="0"
        runat="server" BackgroundCssClass="modalBackground">
  <div class="modalPopup">
     Loading <img src="indicator.gif" align="middle" />

To see how it works, please check out the demo website I have included in the download. The ModalUpdateProgress control supports all the features that UpdateProgress has, including associating the ModalUpdateProgress with an UpdatePanel.

The control passed testing under IE6/7 and Firefox 2.0. Please leave your comments here if you find any problems.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Ting Huang
United States United States
Currently playing Wii...Just love it!

Comments and Discussions

QuestionenableSessionState... Pin
Kim, Eun-Sung14-Jul-16 17:15
MemberKim, Eun-Sung14-Jul-16 17:15 
QuestionMedium Trust Environment Pin
darenh25-Jan-12 0:12
Memberdarenh25-Jan-12 0:12 
QuestionAbout the code Pin
Ali Al Omairi(Abu AlHassan)18-Jun-11 22:47
professionalAli Al Omairi(Abu AlHassan)18-Jun-11 22:47 
GeneralMy vote of 5 Pin
octavio reyes15-Jun-11 5:56
Memberoctavio reyes15-Jun-11 5:56 
GeneralMy vote of 4 Pin
suren.info25-May-11 21:15
Membersuren.info25-May-11 21:15 
GeneralMy vote of 5 Pin
dpjn31623-Sep-10 5:40
Memberdpjn31623-Sep-10 5:40 
GeneralNo DocType No Progress Modal [SOLVED] Pin
Ramkrishna Barot16-Sep-10 8:32
MemberRamkrishna Barot16-Sep-10 8:32 
GeneralError Sys.ArgumentUndefinedException Pin
Federicko23-Jul-10 2:06
MemberFedericko23-Jul-10 2:06 
GeneralModalupdateprogress not working Pin
prakk8827-Jan-10 1:21
Memberprakk8827-Jan-10 1:21 
GeneralKB927917 With ModalUpdateProgress Pin
Danila Korablin21-Jan-10 0:14
MemberDanila Korablin21-Jan-10 0:14 
General"Back" button navigation not working with ModalUpdateProgress Pin
im1dermike13-Nov-09 10:58
Memberim1dermike13-Nov-09 10:58 
GeneralLicense Pin
crashytje30-Jul-09 22:43
Membercrashytje30-Jul-09 22:43 
GeneralHandler was not added sys.ui.domevent.addhandler getting this issue. Pin
Member 350147124-Jun-09 1:24
MemberMember 350147124-Jun-09 1:24 
Questionother elements on the page NOT disabled when the ModalUpdateProgress is shown Pin
aparna guggilla7-Apr-09 19:49
Memberaparna guggilla7-Apr-09 19:49 
QuestionIs there any way to use it for all the requests made to server. Pin
Saurabh Agrawall3-Apr-09 2:28
MemberSaurabh Agrawall3-Apr-09 2:28 
QuestionDelay in Grayed out the background Pin
IamMohan8-Feb-09 20:18
MemberIamMohan8-Feb-09 20:18 
GeneralGreat [modified] Pin
muencfra11-Nov-08 6:01
Membermuencfra11-Nov-08 6:01 
GeneralRe: Great Pin
Jon Selby7-Dec-08 23:58
MemberJon Selby7-Dec-08 23:58 
QuestionNeed other form of display too... Pin
SEKH it29-Oct-08 6:31
MemberSEKH it29-Oct-08 6:31 
QuestionDynamic message display? Pin
conraba20-Oct-08 6:56
Memberconraba20-Oct-08 6:56 
GeneralModalUpdateProgress problem using custom control Pin
gigi746-Oct-08 22:48
Membergigi746-Oct-08 22:48 
QuestionAssembly does not allow partially trusted callers Pin
Prishalan24-Sep-08 4:31
MemberPrishalan24-Sep-08 4:31 
AnswerRe: Assembly does not allow partially trusted callers Pin
Member 43434843-Jun-09 19:31
MemberMember 43434843-Jun-09 19:31 
GeneralRe: Assembly does not allow partially trusted callers Pin
logicaldna15-Jun-09 22:06
Memberlogicaldna15-Jun-09 22:06 
QuestionWhich ajax library are you using here? Pin
efinkelb25-Jul-08 6:41
Memberefinkelb25-Jul-08 6:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.