Create a web project, add a new project> HTML page, and name it progressbar.htm. The content is as follows:
Code
<! 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)
{
// Center progress bar
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 progress bar percentage
Progressbar. style. Width = Pos + " % " ;
Progresstext. innerhtml = Pos + " % " ;
}
// Hide progress bar after completion
Function Setcompleted ()
{
Progressbarside. style. Display = " None " ;
}
</ Script >
</ Head >
< Body >
< Div ID = "Progressbarside" 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:
Code
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 ()
{
// Progressbar.htm display progress bar Interface
String Templatefilename = Path. Combine (server. mappath ( " . " ), " Progressbar.htm " );
Streamreader = 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 ()
{< br> string jsblock = " " ;< br> response. write (jsblock);
response. flush ();
}
private void page_load ( Object sender, system. eventargs e)
{< br> beginprogress ();
for ( int I = 1 ; I <= 100 ; I + )
{< br> setprogress (I);
//Here, we use thread sleep to replace actual operations, such as loading data.
System. Threading. thread. Sleep (50);
}
Finishprogress ();
}
}