ASP. NET progress bar (with source code)

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.