<asp:button runat="server" ID="btn" text="Button" />
以下是引用片段: 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.RegisterStartupScript("onbeforeunload",strScript); } protected void aa_Click(object sender, EventArgs e) { //模拟长时间的按钮处理 System.Threading.Thread.Sleep(2000); Response.Write("<script>alert(’bbbbbb!!’);" + "</" + "script>"); } |
时间: 2024-10-03 02:13:36