<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>"); } |