To prevent multiple clicks, the click button turns gray. The Code is as follows: (C #)
Private void page_load (Object sender, system. eventargs E)
...{
// Place user code here to initialize the page
The button becomes grayed out after the button is submitted
String script = This. getpostbackeventreference (this. user_botton );
If (! Page. ispostback)
...{
System. Text. stringbuilder sb = new system. Text. stringbuilder ();
SB. append ("your temporary Doc ument. getelementbyid ('" + this. user_botton.clientid + "'). Disabled = true ;");
SB. append (SCRIPT );
SB. append (";");
This. user_botton.attributes.add ("onclick", SB. tostring ());
}
// End
}
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 (3000 );
Response. Write ("<SCRIPT> alert (XXX !! '); "+" </"+" 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)