前台:
<asp:button runat="server" ID="btn" text="Button" OnClick="aa_Click" />
后台
public void page_load(Object obj, EventArgs e)
{
btn.Attributes.Add("onclick", "state=true;");
StringBuilder sb = new StringBuilder();
sb.Append("if (!state) return;");
sb.Append("var button=document.getElementById('btn');");
sb.Append("button.value='Please Wait...';");
sb.Append("document.body.style.cursor='wait';");
sb.Append("button.disabled=true;");
string strScript = "<script>";
strScript = strScript + "var state=false;";
//将函数绑定到页面的onbeforeunload事件:
strScript = strScript + "window.attachEvent('onbeforeunload',function(){" + sb.ToString() + "});";
strScript = strScript + "</" + "script>";
Page.ClientScript.RegisterStartupScript(typeof(_Default),"onbeforeunload", strScript); //typeof(_Default)为默认的类名,要改的。
}
protected void aa_Click(object sender, EventArgs e)
{
//模拟长时间的按钮处理
System.Threading.Thread.Sleep(2000);
Response.Write("<script>alert('bbbbbb!!');" + "</" + "script>");
}