asp.net to prevent malicious refresh or multiple click of a button

Source: Internet
Author: User
Tags net

<asp:button runat= "Server" id= "btn" text= "button"/>

The following is a reference fragment:
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;";
To bind a function to a page's onbeforeunload event:
Strscript=strscript + "window.attachevent (' onbeforeunload ', function () {" +SB. ToString () + "});";
Strscript=strscript + "</" + "script>";
Page.registerstartupscript ("onbeforeunload", strscript);
}
protected void Aa_click (object sender, EventArgs e)
{
Simulate a long time button processing
System.Threading.Thread.Sleep (2000);
Response.Write ("<script>alert (' bbbbbb!! ');" + "</" + "script>");
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.