Provided hereCodeIt is used to disable all the buttons on the Asp.net page after a button is clicked, thus preventing multiple submissions due to the submission delay. Based on the previous onceclickbutton script.
// Code preventing multiple page submissions in ASP. NET: javascript <script language = "JavaScript"> <! -- Function disableothersubmit (){
VaR OBJ = event. srcelement;
VaR objs = Document. getelementsbytagname ('input ');
For (VAR I = 0; I <objs. length; I ++)
{
If (objs [I]. type. tolowercase () = 'submit ')
{
Objs [I]. Disabled = true;
}
}
} // --> </SCRIPT> // code preventing multiple page submissions in ASP. NET: Asp. netpublic class preventmulticlick: system. Web. UI. Page {
Protected system. Web. UI. webcontrols. Button button1; protected system. Web. UI. webcontrols. Button button2;
Protected system. Web. UI. webcontrols. linkbutton linkbutton1; protected system. Web. UI. webcontrols. Button button3; private void page_load (Object sender, system. eventargs E)
{
This. getpostbackeventreference (this. button3 );
// Ensure that _ dopostback (eventtarget, eventargument) is correctly registered if (! Ispostback)
{
System. Text. stringbuilder sb = new system. Text. stringbuilder ();
SB. append ("If (typeof (page_clientvalidate) = 'function ')
{
If (page_clientvalidate () = false)
{
Return false;
}
} "); // Ensure that the execution of the verification function sb. append (" If (window. Confirm ('Are you sure? ') = False) return false ;");
// Customize the client script sb. append ("disableothersubmit ();");
// Disable all submit buttons sb. append (this. getpostbackeventreference (this. button3 ));
// Submit with _ dopostback to ensure that the server-side Click Event of the button executes sb. append (";");
Button3.attributes. Add ("onclick", SB. tostring ());
}
} # Region web form designer generated code override protected void oninit (eventargs E)
{
/// Codegen: This call is required by the ASP. NET web form designer. // initializecomponent ();
Base. oninit (E );
}
/// <Summary> /// required method for designer support-do not modify // the contents of this method with the code editor. /// </Summary> private void initializecomponent ()
{
This. button3.click + = new system. eventhandler (this. button3_click); this. Load + = new system. eventhandler (this. page_load );
}
# Endregion private void button3_click (Object sender, system. eventargs E)
{
System. Threading. thread. Sleep (3000 );
Response. Write ("Hello world! ");
}
} Here, only disable all the submit buttons. I think other submit controls can also be disable in a similar way.
The preceding code is implemented in ASP. NET to prevent multiple page submissions.