Document directory
- The progress bar is displayed when the Asp. Net application loads the page for a long time.
The progress bar is displayed when the Asp. Net application loads the page for a long time.
In Asp. net Web applications load pages for a long time, the progress bar is displayed. Although it is a false progress bar, it cannot reflect the loading progress in real time, but it can tell the user that the page is being loaded, so that you do not mistakenly think that the system is faulty or crashed.
Create a new Web project and add four files: default.htm?progressbar.aspx?second.aspx=common.css. The Default.htm page has a hyperchain. Click it and load the Progressbar first. aspx. After loading, load Second. aspx, because Second. the main thread of Page_Load is suspended for 10 seconds, so the progress bar is still displayed. aspx.
The Code is as follows:
Default.htm
Code
Progressbar. aspx (HTML)
[Copy to clipboard]
CODE:
<% @ Page language = "c #" Codebehind = "Progressbar. aspx. cs" AutoEventWireup = "false" Inherits = "WebApp. Progressbar" %>
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<Title> progress bar </title>
<Meta name = "GENERATOR" Content = "Microsoft Visual Studio. NET 7.1">
<Meta name = "CODE_LANGUAGE" Content = "C #">
<Meta name = "vs_defaultClientScript" content = "JavaScript">
<Meta name = "vs_targetSchema" content = "http://schemas.microsoft.com/intellisense/ie5";>
<Link rel = "stylesheet" type = "text/css" href = "common.css"/>
<% String strUrl = Request. Params ["U"]; %>
<META http-equiv = Refresh content = "0; URL = <% = strUrl %>">
<Script language = "javascript">
Var I = 0;
Function setPgb (pgbID, pgbValue)
{
If (pgbValue <= 100)
{
If (lblObj = document. getElementById (pgbID + '_ label '))
{
LblObj. innerHTML = pgbValue + '%'; // change the label value
}
If (pgbObj = document. getElementById (pgbID ))
{
Var divChild = pgbObj. children [0];
PgbObj. children [0]. style. width = pgbValue + "% ";
}
Window. status = "Data Reading" + pgbValue + "%, please wait ...";
}
If (pgbValue = 100)
Window. status = "Data Reading completed ";
}
Function showBar ()
{
SetPgb ('pgbmain', I );
I ++;
}
</Script>
</HEAD>
<BODY onload = "setInterval ('showbar () ', 100)">
<TABLE id = "Table1" style = "WIDTH: 760px" cellSpacing = "0" cellPadding = "0" align = "center"
Border = "0">
& Lt; TR height = "400" & gt;
<TD vAlign = "middle" align = "center">
<DIV class = "bi-loading-status" id = "proBar" style = "LEFT: pixel PX; WIDTH: 300px; TOP: 278px; HEIGHT: 44px">
<DIV class = "text" id = "pgbMain_label" align = "left"> </DIV>
<DIV class = "progress-bar" id = "pgbMain" align = "left">
<DIV style = "WIDTH: 10%"> </DIV>
</DIV>
</DIV>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
Second. aspx (code-behind)
[Copy to clipboard]
CODE:
Using System;
Using System. Collections;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Web;
Using System. Web. SessionState;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. HtmlControls;
Namespace WebApp
{
/// <Summary>
/// Summary of Second.
/// </Summary>
Public class Second: System. Web. UI. Page
{
Private void Page_Load (object sender, System. EventArgs e)
{
// Place user code here to initialize the page
System. Threading. Thread. Sleep (10000 );
}
# Code generated by region Web Form Designer
Override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP. NET Web form designer.
//
InitializeComponent ();
Base. OnInit (e );
}
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void InitializeComponent ()
{
This. Load + = new System. EventHandler (this. Page_Load );
}
# Endregion
}
}
Common.css
[Copy to clipboard]
CODE:
. Bi-loading-status {
/* Position: absolute ;*/
Width: 150px;
Padding: 1px;
Overflow: hidden;
}
. Bi-loading-status. text {
White-space: nowrap;
Overflow: hidden;
Width: 100%;
Text-overflow: ellipsis;
Padding: 1px;
}
. Bi-loading-status. progress-bar {
Border: 1px solid ThreeDShadow;
Background: window;
Height: 10px;
Width: 100%;
Padding: 1px;
Overflow: hidden;
}
. Bi-loading-status. progress-bar div {
Background: Highlight;
Overflow: hidden;
Height: 100%;
Filter: Alpha (Opacity = 0, FinishOpacity = 100, Style = 1, StartX = 0, StartY = 0, FinishX = 100, FinishY = 0 );
}