对于长时间装载的ASP.NET页面,如何在客户端浏览器中显示进度?

简介:
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;
using  System.Threading; 

namespace  Exercise
{
    
/// <summary>
    
/// WebForm2 的摘要说明。
    
/// </summary>

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


        }


        
#region Web 窗体设计器生成的代码
        
override protected void OnInit(EventArgs e)
        
{
            
//
            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            
//
            InitializeComponent();
            
base.OnInit(e);
        }

        
        
/// <summary>
        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
        
/// 此方法的内容。
        
/// </summary>

        private void InitializeComponent()
        
{    
            
this.Load += new System.EventHandler(this.Page_Load);
        }

        
#endregion

    }

}

<% @ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="Exercise.WebForm2"  %>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"  >
< HTML >
    
< HEAD >
        
< title > WebForm2 </ 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" >
        
< script  language ="javascript" >
        HideWait();
        
</ script >
    
</ HEAD >
    
< body  MS_POSITIONING ="GridLayout" >
        
< form  id ="Form1"  method ="post"  runat ="server" >
            
&nbsp;
        
</ form >
    
</ body >
</ HTML >
分类:  IIS, C# Asp.net

本文转自快乐就好博客园博客,原文链接:http://www.cnblogs.com/happyday56/archive/2008/12/27/1363413.html,如需转载请自行联系原作者
相关文章
|
2月前
|
缓存 JavaScript
vue阻止浏览器刷新和关闭页面提示
使用场景:在使用vuex进行缓存管理时,页面的缓存会随着页面关闭而消失,如果缓存动作仍在进行中,关闭页面会导致数据丢失,此时需要阻止页面关闭
73 3
|
3月前
|
数据采集 Web App开发 JSON
浏览器插件:WebScraper基本用法和抓取页面内容(不会编程也能爬取数据)
本文以百度为实战案例演示使用WebScraper插件抓取页面内容保存到文件中。以及WebScraper用法【2月更文挑战第1天】
139 2
浏览器插件:WebScraper基本用法和抓取页面内容(不会编程也能爬取数据)
|
6天前
|
开发框架 .NET 中间件
七天.NET 8操作SQLite入门到实战 - (2)第七天Blazor班级管理页面编写和接口对接
七天.NET 8操作SQLite入门到实战 - (2)第七天Blazor班级管理页面编写和接口对接
|
4月前
|
Web App开发 前端开发 搜索推荐
Chrome 浏览器中的一个隐藏设置页面
Chrome 浏览器中的一个隐藏设置页面
109 8
|
29天前
【超实用】Angular如何修改当前页面网页浏览器url后面?param1=xxx&param2=xxx参数(多用于通过浏览器地址参数保存用户当前操作状态的需求),实现监听url路由切换、状态变化。
【超实用】Angular如何修改当前页面网页浏览器url后面?param1=xxx&param2=xxx参数(多用于通过浏览器地址参数保存用户当前操作状态的需求),实现监听url路由切换、状态变化。
|
1月前
|
搜索推荐 前端开发 UED
html页面实现自动适应手机浏览器(一行代码搞定)
html页面实现自动适应手机浏览器(一行代码搞定)
23 0
|
2月前
|
Web App开发 缓存 网络协议
|
4月前
|
搜索推荐 前端开发 UED
html页面实现自动适应手机浏览器(一行代码搞定)
html页面实现自动适应手机浏览器(一行代码搞定)
66 0
|
4月前
|
缓存 网络协议 前端开发
面试题:浏览器中输入URL返回页面过程?
面试题:浏览器中输入URL返回页面过程?
90 0