Multiple clicks of the preventive button

Source: Internet
Author: User

Today, I am commenting on a news system.

I think of the question that prevented the "Submit" button from being clicked multiple times.

(Prevent multiple clicks of a submit button in ASP. NET ).

In the past, this type of question was always solved by the relocation page.

This time I want to find a permanent solution.

I found someCodeAnd selected some better modifications.

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

// Bind the function to the onbeforeunload event on the page:

Strscript = strscript + "window. attachevent ('onbeforeunload', function () {" + sb. tostring () + "});";

Strscript = strscript + "</" + "script> ";

Page. registerstartupscript ("onbeforeunload", strscript );

}

Private void submit_click (Object sender, eventargs e ){

// Simulate button processing for a long time

System. Threading. thread. Sleep (2000 );

Response. Write ("<SCRIPT> alert ('bbbbbb !! '); "+" </"+" Script> ");

}

<Asp: button id = "BTN" text = "Submit" onclick = "submit_click" runat = "server"/>

The modified example is to put the button in an invalid state for a certain period of time after submission.

It can only prevent the accidental clicks caused by users who are impatient due to slow network speeds.

There is still no solution for multiple submissions formed by malicious refresh.

(However, the onbeforeunload event on the page should be used to solve the problem)

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.