Create a web project, add a new project> HTML page, and name it progressbar.htm. The content is as follows:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml" id = "mainwindow">
<Head>
<Title> No title page </title>
<Script language = "JavaScript">
Function setporgressbar (POS)
{
// Set the progress bar to center
VaR screenheight = Window ["mainwindow"]. offsetheight;
VaR screenwidth = Window ["mainwindow"]. offsetwidth;
Progressbarside. style. width = math. Round (screenwidth/2 );
Progressbarside. style. Left = math. Round (screenwidth/4 );
Progressbarside. style. Top = math. Round (screenheight/2 );
Progressbarside. style. Height = "21px ";
Progressbarside. style. Display = "";
// Set the progress bar percentage
Progressbar. style. width = POS + "% ";
Progresstext. innerhtml = POS + "% ";
}
// hide the progress bar after completion
function setcompleted ()
{< br> progressbarside. style. display = "NONE ";
}< br>
Style = "position: absolute; Height: 21x; width: 100px; color: Silver; border-width: 1px; border-style: solid; display: none">
<Div id = "progressbar" style = "position: absolute; Height: 21px; width: 0%; Background-color: # 3366ff"> </div>
<Div id = "progresstext" style = "position: absolute; Height: 21px; width: 100%; text-align: Center"> </div>
</Div>
</Body>
</Html>
BackgroundCode, Default. aspx. CS:
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. Threading;
Using system. IO;
Public partial class _ default: system. Web. UI. Page
{
Private void beginprogress ()
{
// Progress progressbar.htm display progress bar Interface
String templatefilename = path. Combine (server. mappath ("."),
"Progressbar.htm ");
Streamreader reader = new streamreader
(@ Templatefilename, system. Text. encoding. getencoding ("gb2312 "));
String html = reader. readtoend ();
Reader. Close ();
Response. Write (HTML );
Response. Flush ();
}
Private void setprogress (INT percent)
{
String jsblock = "<SCRIPT> setporgressbar ('" + percent. tostring ()
+ "'); </SCRIPT> ";
Response. Write (jsblock );
Response. Flush ();
}
Private void finishprogress ()
{
String jsblock = "<SCRIPT> setcompleted (); </SCRIPT> ";
Response. Write (jsblock );
Response. Flush ();
}
Private void page_load (Object sender, system. eventargs E)
{
Beginprogress ();
For (INT I = 1; I <= 100; I ++)
{
Setprogress (I );
// Replace the actual operation with thread sleep, such as loading data.
System. Threading. thread. Sleep (50 );
}
Finishprogress ();
}
}