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)