UpdateProgress control which is included with AjaxExtentions works with UpdatePanel control to keep users informed about the progress of the partial postback.
UpdateProgress is important for users to know the current process which is processed by UpdatePanel , so that users is going to wait until the process has completed, clicking a button more than one time or refreshing the page is a bad action usually taken by users in the same situations.
So, I have developed this UpdateProgress to prevent users from preforming any action until UpdatePanel progress is complete. This class is a web control that overrides the UpdateProgress template and inject a modal template which is like AjaxModalPopupExtender, disables page controls until the process is complete.
namespace AjaxedControls
{
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
///
/// Summary description for AjaxUpdateProgress
///
public class AjaxUpdateProgress : Control
{
UpdateProgress ajaxUpdateProgress;
protected override void OnLoad(EventArgs e)
{
ajaxUpdateProgress = new UpdateProgress();
ajaxUpdateProgress.ID = "ajaxUpdateProgress";
ajaxUpdateProgress.DisplayAfter = 0;
ajaxUpdateProgress.ProgressTemplate = new CustomProgressTemplate(_loadingHTMLText);
this.Controls.Add(ajaxUpdateProgress);
}
protected override void Render(HtmlTextWriter writer)
{
//For flexible use (only one .cs file) i added the css style script here.
//If you are to compile this control into a separate assembly, it is better to move this script to an external .css file.
writer.Write(@"
");
base.Render(writer);
}
#region Properties
string _loadingHTMLText = "Loading...";
[Description("HTML text displayed in the loading area.")]
[DefaultValue("Loading...")]
public string LoadingHTMLText
{
set
{
_loadingHTMLText = value;
}
get
{
return _loadingHTMLText;
}
}
Boolean _renderCss = true;
[Description("Gets or sets whether to render css styles for the loading text, else you can add your custom styles to the page.")]
[DefaultValue(true)]
public Boolean RenderCss
{
get { return _renderCss; }
set { _renderCss = value; }
}
#endregion
}
///
/// Progress template for AjaxUpdateProgress control.
///
internal class CustomProgressTemplate : ITemplate
{
internal CustomProgressTemplate() { }
internal CustomProgressTemplate(string loadingHTMLText)
{
_loadingHTMLText = loadingHTMLText;
}
#region ITemplate Members
public void InstantiateIn(Control container)
{
//Override UpdateProgress progress template.
container.Controls.Add(new LiteralControl(@"
{0}
".Replace("{0}", _loadingHTMLText)
));
}
string _loadingHTMLText;
public string LoadingHTMLText
{
set
{
_loadingHTMLText = value;
}
}
#endregion
}
}
39e24958-0d03-453c-ad77-7196da18b37b|2|5.0