Click here to Skip to main content
15,891,253 members
Articles / Web Development / HTML5

AJAX Progress Bar for ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.80/5 (33 votes)
11 Jun 2014CPOL4 min read 170.8K   8K   51  
Async Progress Indicator with Messages and OnComplete Event
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;

[assembly: WebResource("hmlib.Web.UI.Controls.ProgressBar.ProgressBar.js", "text/javascript")]
namespace hmlib.Web.UI.Controls
{
	[ToolboxData("<{0}:ProgressBar runat=server></{0}:ProgressBar>")]
	[ToolboxBitmap(typeof(ProgressBar), "ProgressBar.ProgressBar.ico")]
	public partial class ProgressBar : ScriptControl
	{
		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);
			ResourceHandler.RegisterjQuery(this);
			//ResourceHandler.RegisterJSON(this);
			ResourceHandler.Register_hmlib(this);
		}
		protected override void Render(HtmlTextWriter writer)
		{
			if (DesignMode)
			{
				this.Style["cursor"] = "default";
				this.Style["border"] = "solid 1px black";
				this.Style["text-align"] = "center";
				this.Controls.Clear();
				this.Controls.Add(new LiteralControl("[" + this.ID + "]"));
				base.Render(writer);
				return;
			}
			if (!this.Visible) return;
			this.Attributes.CssStyle.Clear();
			base.Render(writer);
			//this.Attributes["data-completed"] = (this.Progress.Value >= 1) ? "1" : "0";
			//writer.Write("<span>Hello</span>");
		}
		protected override IEnumerable<ScriptDescriptor> GetScriptDescriptors()
		{
			ScriptControlDescriptor descriptor = new ScriptControlDescriptor("hmlib.Web.UI.Controls.ProgressBar.ProgressBar", this.ClientID);
			//descriptor.AddProperty("CssClass", this.CssClass);			
			descriptor.AddProperty("ServicePath", ResolveUrl(this.ServicePath));
			descriptor.AddProperty("Service_GetMethod", this.Service_GetMethod);
			descriptor.AddProperty("ProgressId", this.ProgressId);
			descriptor.AddProperty("Interval", this.Interval);
			descriptor.AddProperty("SingleLine", this.SingleLine);
			descriptor.AddProperty("Completed", this.Progress.Value >= 1);
			descriptor.AddProperty("OnClientComplete", this.OnClientComplete);
			if (this.MessageTarget != null)
			{
				descriptor.AddProperty("MessageTargetId", this.MessageTarget.ClientID);
				descriptor.AddProperty("MessageTargetType", this.MessageTarget.GetType().Name.ToLower());
			}
			if (this.ProgressControl != null)
			{
				descriptor.AddProperty("ProgressControlId", this.ProgressControl.ClientID);
			}
			if (this.Complete != null)
			{
				descriptor.AddProperty("CompletePostbackReference", Page.ClientScript.GetPostBackEventReference(this, "Complete"));
				//this.Attributes["data-complete_postback_reference"] = Page.ClientScript.GetPostBackEventReference(this, "Complete");
			}
			if (!this.Width.IsEmpty)
			{
				descriptor.AddProperty("Width", this.Width.ToString());
			}
			yield return descriptor;
		}
		// Generate the script reference
		protected override IEnumerable<ScriptReference> GetScriptReferences()
		{
			yield return new ScriptReference("hmlib.Web.UI.Controls.ProgressBar.ProgressBar.js", this.GetType().Assembly.FullName);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer (Senior) FDK
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions