Click here to Skip to main content
15,884,176 members
Articles / Web Development / HTML
Article

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 912.7K   5.4K   156   209
A progress indicator control that works in a modal popup style.

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

C#
/// <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:

HTML
<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


Written By
United States United States
Currently playing Wii...Just love it!

Comments and Discussions

 
AnswerRe: Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method. Pin
Abdulhamit Mabocoglu24-Jan-07 12:50
Abdulhamit Mabocoglu24-Jan-07 12:50 
GeneralRe: Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method. Pin
t0r0124-Jan-07 23:11
t0r0124-Jan-07 23:11 
AnswerRe: Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method. Pin
Ting Huang25-Jan-07 16:53
Ting Huang25-Jan-07 16:53 
GeneralRe: Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method. Pin
Abdulhamit Mabocoglu25-Jan-07 20:57
Abdulhamit Mabocoglu25-Jan-07 20:57 
AnswerRe: Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method. Pin
Ting Huang26-Jan-07 14:24
Ting Huang26-Jan-07 14:24 
AnswerRe: Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method. Pin
lessid31-Jan-07 3:01
lessid31-Jan-07 3:01 
GeneralRe: Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method. Pin
amiller127-Feb-07 16:54
amiller127-Feb-07 16:54 
GeneralRe: Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method. Pin
fdepicciotto19-Mar-07 12:53
fdepicciotto19-Mar-07 12:53 
GeneralRe: Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method. Pin
Ismail Mayat20-Mar-07 5:26
Ismail Mayat20-Mar-07 5:26 
QuestionRe: Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method. Pin
jamierfoster29-Feb-08 10:30
jamierfoster29-Feb-08 10:30 
GeneralRe: Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method. Pin
jamierfoster29-Feb-08 12:27
jamierfoster29-Feb-08 12:27 
GeneralRe: Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method. Pin
scanbix30-Nov-09 4:04
scanbix30-Nov-09 4:04 
GeneralFade In Pin
n1ck0s23-Jan-07 8:44
n1ck0s23-Jan-07 8:44 
GeneralGood tips Pin
WaYdotNET ( Carlo Bertini)18-Jan-07 1:20
WaYdotNET ( Carlo Bertini)18-Jan-07 1:20 
NewsUpdated Version Pin
Ting Huang3-Jan-07 20:30
Ting Huang3-Jan-07 20:30 
NewsRe: Updated Version Pin
Ting Huang11-Jan-07 7:41
Ting Huang11-Jan-07 7:41 
GeneralRe: Updated Version Pin
AnksuNico15-Jan-07 0:00
AnksuNico15-Jan-07 0:00 
QuestionRe: Updated Version Pin
stephenclaybrandt15-Jan-07 6:57
stephenclaybrandt15-Jan-07 6:57 
AnswerRe: Updated Version Pin
Ting Huang15-Jan-07 7:57
Ting Huang15-Jan-07 7:57 
GeneralRe: Updated Version Pin
codegalaxy22-Jan-07 18:36
codegalaxy22-Jan-07 18:36 
AnswerRe: Updated Version Pin
Ting Huang22-Jan-07 20:02
Ting Huang22-Jan-07 20:02 
GeneralCancel Button make a page refresh with javascript error in Ajax 1.0 RC Pin
Abdulhamit Mabocoglu16-Dec-06 21:07
Abdulhamit Mabocoglu16-Dec-06 21:07 
AnswerRe: Cancel Button make a page refresh with javascript error in Ajax 1.0 RC Pin
Abdulhamit Mabocoglu18-Dec-06 11:06
Abdulhamit Mabocoglu18-Dec-06 11:06 
NewsRe: Cancel Button make a page refresh with javascript error in Ajax 1.0 RC Pin
Abdulhamit Mabocoglu19-Dec-06 5:02
Abdulhamit Mabocoglu19-Dec-06 5:02 
AnswerRe: Cancel Button make a page refresh with javascript error in Ajax 1.0 RC Pin
Abdulhamit Mabocoglu20-Dec-06 12:08
Abdulhamit Mabocoglu20-Dec-06 12:08 

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.