It's very tough to create a progress bar in an ASP.NET application (or any web app for that matter), because of the disconnected nature of a web app. Generally, a process is happening on the server, so the client-side is not even rendered yet.
Here's a little control that I use that might help you out:
The control:
--------------
using System;
using System.Text;
using System.Web.UI;
namespace Tester
{
[ToolboxData("<{0}:BusyControl runat=server></{0}:BusyControl>")]
public class BusyControl : System.Web.UI.WebControls.WebControl
{
// Found at:
// C:\Program Files\Microsoft Office\CLIPART\PUB60COR\AG00011_.GIF
private string m_ImageFilePath = @"AG00011_.GIF";
public BusyControl()
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
StringBuilder sbScript = new StringBuilder();
sbScript.Append("\n");
sbScript.Append("<div id='busyControlDiv' align='center' style='z-index:5000;'>\n");
sbScript.Append("<br>\n");
sbScript.Append("<br>\n");
sbScript.Append("<br>\n");
sbScript.Append("<br>\n");
sbScript.Append("<br>\n");
sbScript.Append(" <table align='center' bgcolor='ButtonFace' border='2' bordercolor='ButtonShadow' bordercolordark='ButtonShadow' ");
sbScript.Append(" bordercolorlight='InactiveBorder' rules='none' cellpadding='10' cellspacing='0' width='30%'>\n");
sbScript.Append(" <tr>\n");
sbScript.Append(" <td width='100%' align='center' valign='center' nowrap>\n");
sbScript.Append(" <font size='3' color='Black'>\n");
sbScript.Append(" <b>Working...</b>\n");
sbScript.Append(" </font>\n");
sbScript.Append(" <br>\n");
sbScript.Append(" <img src='" + this.m_ImageFilePath + "' border='0'>\n");
sbScript.Append(" </td>\n");
sbScript.Append(" </tr>\n");
sbScript.Append(" </table>\n");
sbScript.Append("</div>\n");
this.Page.Response.Write(sbScript.ToString());
this.Page.Response.Flush();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
StringBuilder sbScript = new StringBuilder();
sbScript.Append("\n");
sbScript.Append("<script language=\"JavaScript\" type=\"text/javascript\">\n");
sbScript.Append("<!--\n");
// W3C DOM
sbScript.Append("if ( document.getElementById )\n");
sbScript.Append(" document.getElementById('busyControlDiv').style.display = 'none';\n");
// IE 4
sbScript.Append("else if ( document.all )\n");
sbScript.Append(" document.all.busyControlDiv.style.display = 'none';\n");
// NS 4
sbScript.Append("else if ( document.layers )\n");
sbScript.Append(" document.busyControlDiv.display = 'none';\n");
sbScript.Append("//-->\n");
sbScript.Append("</script>\n");
this.Page.Response.Write(sbScript.ToString());
}
}
}
In the page to use it:
-----------------------
At the top of the aspx file add:
<%@ Register TagPrefix="cc1" Namespace="Tester" Assembly="Tester" %>
Between the <form> tags add:
<cc1:BusyControl id="BusyControl1" runat="server"></cc1:BusyControl>
In the CodeBehind, Page_Load event handler:
private void Page_Load(object sender, System.EventArgs e)
{
// Here we just wait 10 seconds to emulate a lengthy process...
TimeSpan waitTime = new TimeSpan(0, 0, 0, 10);
System.Threading.Thread.Sleep(waitTime);
// Indicate that the process is done...
this.Response.Write("The lengthy process has completed and the page has now fully loaded.");
}
NC...