- CODE:
- <asp:button runat="server" ID="btn" text="Button" OnClick="aa_Click" />
- CODE:
- 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>");
- }
预防按钮的多次点击【恶意刷新】
最新推荐文章于 2022-03-17 11:13:10 发布