Click here to Skip to main content
12,751,832 members (30,603 online)
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 21 Aug 2008

Progressbar for long running scripts

, 21 Aug 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Show a progress bar when your code runs for a long time.



I have been looking, to no avail, for an easy way to show a progress bar in ASP.NET that can be updated with C# code-behind, so I built one and think it might be useful to other developers who need to show the progress of a long running code snippet.

Using the code

The progress bar can be placed on any ASP.NET form by just adding a few new functions to your existing code. The colour can be changed by just updating the image used to display the bar.

There are only two functions that need to be included. The first function is to draw the progress bar in a table:

public void CreateInterface()
    //Draw the progress page
    Response.Write("<table width=\"100%\" style=\"font-family:Arial; font-size:12px;" + 
                   "text-align:center\"><tr><td>" + 
                   "<div id='mydiv' style=\"border:solid 1px black\" >" + 
                   "<strong>Progressbar Demo</strong><br /><hr />" +
                   "<table border=\"0\" style=\"font-family:Arial;" + 
                   " font-size:12px;\" width=\"300px\">" + 
                   "<tr><td width=\"100%\" style=\"text-align:center\"" + 
                   "><div id=\"ProgressText\">0%</div>" + 
                   "</td></tr></table>" +
                   "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" " + 
                   "width=\"300px\" height=\"13\">" + 
                   "<tr><td id=\"indicator\" style=\"background-image:url('Progress" + 
                   ddlColour.SelectedItem.Text + ".jpg');" + 
                   " background-repeat:repeat-x\" width=\"0%\">" + 
                   "</td><td width=\"100%\"></td></tr>" + 
    //Insert the scripts for updating
    Response.Write("<script language="\""javascript\">;");

    Response.Write("function ShowProgress(){}");

    Response.Write("function StartShowWait(){ = 'visible';" + 
                   " window.setInterval('ShowProgress()',1000);}");

    Response.Write("function HideWait(){" + 
                   " = 'none';window.clearInterval();}");

    Response.Write("function UpdateIndicator(NewValue) " + 
                   "{ = NewValue +\"%\";" + 
                   " ProgressText.innerText=NewValue + \"%\"}");


    if (!IsPostBack)
        //Hide if first load


The second function is to update the progress bar from your code:

public void UpdateProgressBar(double Text)
    Response.Write("<script>UpdateIndicator(\"" + 
             Convert.ToInt32(Text).ToString() + "\");</script>");


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


About the Author

Wayne Redelinghuys
Web Developer Metrix Software Solutions
South Africa South Africa
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionHow to update progress based on server side task status. Pin
sudipta.india31-May-09 6:40
membersudipta.india31-May-09 6:40 
QuestionWhy boxing? Pin
Guido_d22-Aug-08 4:29
memberGuido_d22-Aug-08 4:29 
AnswerRe: Why boxing? Pin
Wayne Redelinghuys22-Aug-08 4:53
memberWayne Redelinghuys22-Aug-08 4:53 
GeneralPlease Check your formatiing Pin
Abhijit Jana22-Aug-08 0:22
memberAbhijit Jana22-Aug-08 0:22 
GeneralRe: Please Check your formatiing Pin
Wayne Redelinghuys22-Aug-08 4:59
memberWayne Redelinghuys22-Aug-08 4:59 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 22 Aug 2008
Article Copyright 2008 by Wayne Redelinghuys
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid