Click here to Skip to main content
15,884,353 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.1K   8K   51  
Async Progress Indicator with Messages and OnComplete Event
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using hmlib.Web.UI.Controls;

namespace WebTest.ProgressBarTest
{
	public partial class ucStartOnServerSide : System.Web.UI.UserControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (IsPostBack) return;
			this.ProgressBar1.ProgressId = "TestProgress";
		}
		protected void btnStart_Click(object sender, EventArgs e)
		{
			btnStart.Enabled = false;
			rbSpeed.Enabled = false;
			int interval = int.Parse(rbSpeed.SelectedValue);
			Thread thread = new Thread(() => this.StartProgress(ProgressBar1.Progress, interval));
			thread.Start();
		}
		private void StartProgress(Progress progress, int interval)
		{
			int rounds = int.Parse(rbRounds.SelectedValue);
			for (int i = 0; i < rounds; i++)
			{
				progress.SetProgress(0);
				progress.AddMessageLine("Round " + (i + 1) + " started");
				for (int j = 0; j < 100; j++)
				{
					//interval = Math.Max(10, interval - 1);
					double value = .98 * j / 100d;
					progress.SetProgress(value);
					//progress.AddMessageLine(value.ToString());
					Thread.Sleep(interval);
				}
			}
			progress.AddMessageLine("Finished");
			progress.SetProgress(1);
		}
	}
}

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