1. progress bar template file progressbar.htm 1 < Html >
2 < Head >
3 < Title > </ Title >
4 < Script Language = "JavaScript" >
5 // Set progress bar
6 Function Setporgressbar (MSG, POS)
7 {
8 Progressbar. style. Width = Pos + " % " ;
9 Writetext ( " Msg1 " , MSG + " Completed " + Pos + " % " );
10 }
11
12 // Set progress bar completion Information
13 Function Setcompleted (MSG)
14 {
15 If (Msg = "" )
16 Writetext ( " Msg1 " , " Complete. " );
17 Else
18 Writetext ( " Msg1 " , MSG );
19 }
20
21 // Update text display information
22 Function Writetext (ID, STR)
23 {
24 VaR Strtag = ' < Font face = " Verdana, Arial, Helvetica " Size = " 2 " Color = " # Ea9b02 " > < B > ' + Str + ' </ B > </ Font > ';
25 If (Document. All) document. All [ID]. innerhtml = Strtag;
26 }
27 </ Script >
28 </ Head >
29 < Body >
30 < Div ID = "Msg1" > < Font Face = "Verdana, Arial, helvetica" Size = "2" Color = "# Ea9b02" > < B > Loading </ B > </ Font > </ Div >
31 < Div ID = "Progressbarside" Style = "Color: Silver; border-width: 1px; border-style: solid; width: 300px ;" >
32 < Div ID = "Progressbar" Style = "Background-color: # 3366ff; Height: 21px; width: 0% ;" > </ Div >
33 </ Div >
34 </ Body >
35 </ Html >
2. default. aspx. CS
1 Protected Void Page_load ( Object Sender, eventargs E)
2 {
3 // Display progress bar according to progressbar.htm
4 String Templatefilename = Path. Combine (server. mappath ( " . " ), " Progressbar.htm " );
5 Streamreader = New Streamreader (@ templatefilename, system. Text. encoding. getencoding ( " Gb2312 " ));
6 String Html = Reader. readtoend ();
7 Reader. Close ();
8 Response. Write (HTML );
9 Response. Flush ();
10 System. Threading. thread. Sleep ( 200 );
11
12 // Update the progress bar based on the processing status of the processing task
13 String Jsblock;
14 For ( Int I = 1 ; I <= 100 ; I ++ )
15 {
16 System. Threading. thread. Sleep ( 10 );
17 Jsblock = " <SCRIPT> setporgressbar (' " + " A " + I. tostring () + " ',' " + I. tostring () + " '); </SCRIPT> " ;
18
19 Response. Write (jsblock );
20 Response. Flush ();
21 }
22
23 // Processed
24 Jsblock = " <SCRIPT> setcompleted ('processing completed. '); </SCRIPT> " ;
25 Response. Write (jsblock );
26 Response. Flush ();
27 }
3. Run default. aspx. The effect is as follows:
Source code: Progressbar.rar
Address: http://www.cnblogs.com/anjou/archive/2006/10/27/541741.html