代码文件:
使用系统;
使用系统集合;
使用 System.ComponentModel;
使用系统数据;
使用系统绘图;
使用系统.Web;
使用 System.Web.SessionState;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Web.UI.HtmlControls;
使用系统线程;
命名空间 AjaxTest
{
/**//// <摘要>
/// WebForm2 的摘要说明。
/// </摘要>
公共类WebForm2:System.Web.UI.Page
{
受保护的 System.Web.UI.WebControls.Button Button1;
受保护的 System.Web.UI.WebControls.Label Label1;
私人无效Page_Load(对象发送者,System.EventArgs e)
{
Response.Write("<div id='mydiv' >");
响应.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<脚本语言=javascript>;");
Response.Write("vardots = 0;vardotmax=10;function ShowWait()");
Response.Write("{var output;output = '正在加载页面';dots++;if(dots>=dotmax)dots=1;");
Response.Write("for(var x = 0;x < 点;x++){output += '·';}mydiv.innerText = 输出;}");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
Response.Write("window.setInterval('ShowWait()',1000);}");
Response.Write("function HideWait(){mydiv.style.visibility = '隐藏';");
Response.Write("window.clearInterval();}");
Response.Write("StartShowWait();</script>");
Response.Flush();//这一句是最关键的
}
private void Button1_Click(对象发送者, System.EventArgs e)
{
//当点击按钮时,假设请求需要几分钟时间(这里设置为10秒)
System.Threading.Thread.Sleep(10000);
this.Label1.Text = "终于加载完成啦";
}
Web 表单设计器生成的代码#region Web 表单设计器生成的代码
覆盖 protected void OnInit(EventArgs e)
{
//
// CODEGEN: 调用是 ASP.NET Web 表单设计器所必需的。
//
初始化组件();
基.OnInit(e);
}
/**//// <摘要>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 该方法的内容。
/// </摘要>
私有无效InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
页面文件:
<%@ 页面语言="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="AjaxTest.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 过渡//EN" >
<HTML>
<头>
<标题>WebForm2</标题>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<元名称=“CODE_LANGUAGE”内容=“C#”>
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content=" http://schemas.microsoft.com/intellisense/ie5 ">
<脚本>
隐藏等待();
</脚本>
</头>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONTface="宋体">
<asp:Button id="Button1" style="Z-INDEX: 101; 左: 480px; 位置: 绝对; 顶部: 200px" runat="服务器"
Text="按钮"></asp:按钮>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 632px; POSITION: Absolute; TOP: 240px" runat="server">标签</asp:Label></FONT>
</形式>
</正文>
</HTML>
http://fanrsh.cnblogs.com/archive/2006/06/14/425888.html