Click here to Skip to main content
6,636,867 members and growing! (19,686 online)
Email Password   helpLost your password?
Web Development » Ajax and Atlas » Atlas     Intermediate

Atlas: ModalUpdateProgress - An UpdateProgress Control in Modal Popup Style

By Ting Huang

A progress indicator control that works in a modal popup style.
Javascript, XML, HTML, C# 2.0, Windows, .NET 2.0, ASP.NET, WebForms, Ajax, VS2005, Dev
Posted:6 Oct 2006
Updated:26 Jun 2007
Views:236,438
Bookmarked:136 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
34 votes for this article.
Popularity: 6.78 Rating: 4.42 out of 5
3 votes, 9.1%
1

2
2 votes, 6.1%
3
4 votes, 12.1%
4
24 votes, 72.7%
5

Sample Image - ModalUpdateProgress.jpg

Introduction

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():

/// <summary>

/// Gets the script descriptors.

/// </summary>

/// <returns>A list of components, behaviors, and 

/// client controls required

/// for the ModalUpdateProgress control's client functionality

/// </returns>

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;
  }
}

/// <summary>

/// Gets the script references.

/// </summary>

/// <returns>A list of client script library dependencies for the control.

/// </returns>

protected override IEnumerable<ScriptReference> GetScriptReferences()
{
    yield return new ScriptReference("AjaxControls.ModalUpdateProgress.js", "
    AjaxControls");
}

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">
 <ProgressTemplate>
  <div class="modalPopup">
     Loading <img src="indicator.gif" align="middle" />
  </div>
 </ProgressTemplate>
</asp:ModalUpdateProgress>

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.

License

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


Member
Currently playing Wii...Just love it!
Location: United States United States

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 25 of 198 (Total in Forum: 198) (Refresh)FirstPrevNext
General"Back" button navigation not working with ModalUpdateProgress Pinmemberim1dermike10:58 13 Nov '09  
GeneralLicense Pinmembercrashytje22:43 30 Jul '09  
GeneralHandler was not added sys.ui.domevent.addhandler getting this issue. PinmemberMember 35014711:24 24 Jun '09  
Questionother elements on the page NOT disabled when the ModalUpdateProgress is shown Pinmemberaparna guggilla19:49 7 Apr '09  
QuestionIs there any way to use it for all the requests made to server. PinmemberSaurabh Agrawall2:28 3 Apr '09  
QuestionDelay in Grayed out the background PinmemberM-o-h-a-n20:18 8 Feb '09  
GeneralGreat [modified] Pinmembermuencfra6:01 11 Nov '08  
GeneralRe: Great PinmemberMember 373804523:58 7 Dec '08  
QuestionNeed other form of display too... PinmemberSEKH it6:31 29 Oct '08  
GeneralDynamic message display? Pinmemberconraba6:56 20 Oct '08  
GeneralModalUpdateProgress problem using custom control Pinmembergigi7422:48 6 Oct '08  
QuestionAssembly does not allow partially trusted callers Pinmembershalan994:31 24 Sep '08  
AnswerRe: Assembly does not allow partially trusted callers PinmemberMember 434348419:31 3 Jun '09  
GeneralRe: Assembly does not allow partially trusted callers Pinmemberlogicaldna22:06 15 Jun '09  
GeneralWhich ajax library are you using here? Pinmemberefinkelb6:41 25 Jul '08  
GeneralModalpopup does not display..... PinmemberKamalmostofi3:07 2 Jul '08  
GeneralProblem with ModalPopup PinmemberadlionelC7:05 10 Jun '08  
QuestionPossible to show modal progress bar over multiple frame document? Pinmemberbjames0212:47 9 May '08  
GeneralProblem in firefox and safari PinmemberIsmail Mayat7:12 2 May '08  
GeneralGreat Job PinmemberSunny Gurnani9:40 21 Apr '08  
GeneralHandler was not added through the Sys.UI.DomEvent.addHandler method. PinmemberVictor M. Bello A.7:33 4 Apr '08  
GeneralRe: Handler was not added through the Sys.UI.DomEvent.addHandler method. PinmemberVictor M. Bello A.7:40 4 Apr '08  
GeneralRe: Handler was not added through the Sys.UI.DomEvent.addHandler method. PinmemberDPLyonnais9:22 8 May '08  
GeneralGood, thanks!!! Pinmemberkeenth4:59 4 Apr '08  
GeneralThank you! Pinmembershalan9923:53 18 Mar '08  

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

PermaLink | Privacy | Terms of Use
Last Updated: 26 Jun 2007
Editor: Chris Maunder
Copyright 2006 by Ting Huang
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project