对于长时间装载的ASP.NET页面,如何在客户端浏览器中显示进度?
using System;
 using System.Collections;
using System.Collections;
 using System.ComponentModel;
using System.ComponentModel;
 using System.Data;
using System.Data;
 using System.Drawing;
using System.Drawing;
 using System.Web;
using System.Web;
 using System.Web.SessionState;
using System.Web.SessionState;
 using System.Web.UI;
using System.Web.UI;
 using System.Web.UI.WebControls;
using System.Web.UI.WebControls;
 using System.Web.UI.HtmlControls;
using System.Web.UI.HtmlControls;
 using System.Threading;
using System.Threading; 

 namespace Exercise
namespace Exercise
 {
{
 /// <summary>
    /// <summary>
 /// WebForm2 的摘要说明。
    /// WebForm2 的摘要说明。
 /// </summary>
    /// </summary>
 public class WebForm2 : System.Web.UI.Page
    public class WebForm2 : System.Web.UI.Page
 {
    {
 private void Page_Load(object sender, System.EventArgs e)
        private void Page_Load(object sender, System.EventArgs e)
 {
        {
 // 对于长时间装载的ASP.NET页面如何在客户端浏览器中显示进度?
            // 对于长时间装载的ASP.NET页面如何在客户端浏览器中显示进度?
 //对于加载时间比较长的ASP.NET页面,
            //对于加载时间比较长的ASP.NET页面,
 //我们可以在客户端浏览器中显示进度条来显示页面正在装载。下面就是具体的实现过程:
            //我们可以在客户端浏览器中显示进度条来显示页面正在装载。下面就是具体的实现过程:
 if(!IsPostBack)
            if(!IsPostBack)
 {
            {
 Response.Write("<div id='mydiv' >");
                Response.Write("<div id='mydiv' >");
 Response.Write("_");
                Response.Write("_");
 Response.Write("</div>");
                Response.Write("</div>");
 Response.Write("<script>mydiv.innerText = '';</script>");
                Response.Write("<script>mydiv.innerText = '';</script>");
 Response.Write("<script language=javascript>;");
                Response.Write("<script language=javascript>;");
 Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
                Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
 Response.Write("{var output; output = '正在装载页面';dots++;if(dots>=dotmax)dots=1;");
                Response.Write("{var output; output = '正在装载页面';dots++;if(dots>=dotmax)dots=1;");
 Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText =  output;}");
                Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText =  output;}");
 Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
                Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
 Response.Write("window.setInterval('ShowWait()',1000);}");
                Response.Write("window.setInterval('ShowWait()',1000);}");
 Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
                Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
 Response.Write("window.clearInterval();}");
                Response.Write("window.clearInterval();}");
 Response.Write("StartShowWait();</script>");
                Response.Write("StartShowWait();</script>");                
 Response.Flush();
                Response.Flush();
 for(long i=0;i<99999999999;i++) i=i++;
                for(long i=0;i<99999999999;i++) i=i++;
 //or Thread.Sleep(10000);
                //or Thread.Sleep(10000);
 }
            }

 }
        }

 #region Web 窗体设计器生成的代码
        #region Web 窗体设计器生成的代码
 override protected void OnInit(EventArgs e)
        override protected void OnInit(EventArgs e)
 {
        {
 //
            //
 // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
 //
            //
 InitializeComponent();
            InitializeComponent();
 base.OnInit(e);
            base.OnInit(e);
 }
        }
 
        
 /// <summary>
        /// <summary>
 /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
 /// 此方法的内容。
        /// 此方法的内容。
 /// </summary>
        /// </summary>
 private void InitializeComponent()
        private void InitializeComponent()
 {
        {    
 this.Load += new System.EventHandler(this.Page_Load);
            this.Load += new System.EventHandler(this.Page_Load);
 }
        }
 #endregion
        #endregion
 }
    }
 }
}
 
 <%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="Exercise.WebForm2" %>
<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="Exercise.WebForm2" %>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
 <HTML>
<HTML>
 <HEAD>
    <HEAD>
 <title>WebForm2</title>
        <title>WebForm2</title>
 <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
 <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="CODE_LANGUAGE" Content="C#">
 <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_defaultClientScript" content="JavaScript">
 <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
 <script language="javascript">
        <script language="javascript">
 HideWait();
        HideWait();
 </script>
        </script>
 </HEAD>
    </HEAD>
 <body MS_POSITIONING="GridLayout">
    <body MS_POSITIONING="GridLayout">
 <form id="Form1" method="post" runat="server">
        <form id="Form1" method="post" runat="server">
  
             
 </form>
        </form>
 </body>
    </body>
 </HTML>
</HTML>
 
 using System.Collections;
using System.Collections; using System.ComponentModel;
using System.ComponentModel; using System.Data;
using System.Data; using System.Drawing;
using System.Drawing; using System.Web;
using System.Web; using System.Web.SessionState;
using System.Web.SessionState; using System.Web.UI;
using System.Web.UI; using System.Web.UI.WebControls;
using System.Web.UI.WebControls; using System.Web.UI.HtmlControls;
using System.Web.UI.HtmlControls; using System.Threading;
using System.Threading; 
 namespace Exercise
namespace Exercise {
{ /// <summary>
    /// <summary> /// WebForm2 的摘要说明。
    /// WebForm2 的摘要说明。 /// </summary>
    /// </summary> public class WebForm2 : System.Web.UI.Page
    public class WebForm2 : System.Web.UI.Page {
    { private void Page_Load(object sender, System.EventArgs e)
        private void Page_Load(object sender, System.EventArgs e) {
        { // 对于长时间装载的ASP.NET页面如何在客户端浏览器中显示进度?
            // 对于长时间装载的ASP.NET页面如何在客户端浏览器中显示进度? //对于加载时间比较长的ASP.NET页面,
            //对于加载时间比较长的ASP.NET页面, //我们可以在客户端浏览器中显示进度条来显示页面正在装载。下面就是具体的实现过程:
            //我们可以在客户端浏览器中显示进度条来显示页面正在装载。下面就是具体的实现过程: if(!IsPostBack)
            if(!IsPostBack) {
            { Response.Write("<div id='mydiv' >");
                Response.Write("<div id='mydiv' >"); Response.Write("_");
                Response.Write("_"); Response.Write("</div>");
                Response.Write("</div>"); Response.Write("<script>mydiv.innerText = '';</script>");
                Response.Write("<script>mydiv.innerText = '';</script>"); Response.Write("<script language=javascript>;");
                Response.Write("<script language=javascript>;"); Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
                Response.Write("var dots = 0;var dotmax = 10;function ShowWait()"); Response.Write("{var output; output = '正在装载页面';dots++;if(dots>=dotmax)dots=1;");
                Response.Write("{var output; output = '正在装载页面';dots++;if(dots>=dotmax)dots=1;"); Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText =  output;}");
                Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText =  output;}"); Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
                Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; "); Response.Write("window.setInterval('ShowWait()',1000);}");
                Response.Write("window.setInterval('ShowWait()',1000);}"); Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
                Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';"); Response.Write("window.clearInterval();}");
                Response.Write("window.clearInterval();}"); Response.Write("StartShowWait();</script>");
                Response.Write("StartShowWait();</script>");                 Response.Flush();
                Response.Flush(); for(long i=0;i<99999999999;i++) i=i++;
                for(long i=0;i<99999999999;i++) i=i++; //or Thread.Sleep(10000);
                //or Thread.Sleep(10000); }
            }
 }
        }
 #region Web 窗体设计器生成的代码
        #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e)
        override protected void OnInit(EventArgs e) {
        { //
            // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 //
            // InitializeComponent();
            InitializeComponent(); base.OnInit(e);
            base.OnInit(e); }
        } 
         /// <summary>
        /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。
        /// 此方法的内容。 /// </summary>
        /// </summary> private void InitializeComponent()
        private void InitializeComponent() {
        {     this.Load += new System.EventHandler(this.Page_Load);
            this.Load += new System.EventHandler(this.Page_Load); }
        } #endregion
        #endregion }
    } }
} 
 <%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="Exercise.WebForm2" %>
<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="Exercise.WebForm2" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML>
<HTML> <HEAD>
    <HEAD> <title>WebForm2</title>
        <title>WebForm2</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> <script language="javascript">
        <script language="javascript"> HideWait();
        HideWait(); </script>
        </script> </HEAD>
    </HEAD> <body MS_POSITIONING="GridLayout">
    <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server">
        <form id="Form1" method="post" runat="server">  
              </form>
        </form> </body>
    </body> </HTML>
</HTML>
 
                    
                     
                    
                 
                    
                

 
     
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号