asp.net
On the internet to look at a lot of relevant information, referring to the contrast after the collation of their own, made a small example. Able to achieve the background data loading progress in the foreground dynamic update progress bar, progress bar in the center of the page display, in the progress bar to show the percentage, complete the progress after the progress bar hidden. Personal feeling or have a certain reference value, posted out first.
Create a Web project, add a new Item->html page, named Progressbar.htm, which reads:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Untitled Page </title>
<script language= "JavaScript" >
function Setporgressbar (POS)
{
Set Progress Bar 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 progress bar percent
ProgressBar.style.width = pos + "%";
progresstext.innerhtml = pos + "%";
}
Hide Progress bar when finished
function setcompleted ()
{
ProgressBarSide.style.display = "None";
}
</script>
<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>
Background code, 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 ()
{
//Show progress bar interface according to Progressbar.htm
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 <= i++)
{
Setprogress (i);
Thread hibernation is used here instead of the actual operation, such as loading data
System.Threading.Thread.Sleep (50);
}
Finishprogress ();
}
}
The foreground page code is omitted here and you can place any control.