Asp.net implementation progress bar

Source: Internet
Author: User

 

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 ();
}
}

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.