The Code provided here is used to disable all the buttons on the asp.net page after a Button is clicked, thus preventing multiple submissions due to submission delay. Based on the previous onceclickbutton script.
- // Code preventing multiple page submissions in ASP. NET: javascript
- < Script Language="Javascript">
- <! --
- Function disableOtherSubmit ()
- {VarObj=Event. SrcElement;
- VarObjs=Document. GetElementsByTagName ('input ');
- For (varI=0; I< Objs. length; I ++)
- {
- If (objs [I]. type. toLowerCase () = 'submit ')
- {
- Objs [I]. Disabled=True;
- }
- }}
- //-->
- </Script>
- //Code Used in ASP. NET to prevent multiple page submissions: asp.net
- Public ClassPreventMultiClick: System. Web. UI. Page
- {
- ProtectedSystem. Web. UI. WebControls. Button Button1;
- ProtectedSystem. Web. UI. WebControls. Button Button2;
- ProtectedSystem. Web. UI. WebControls. LinkButton LinkButton1;
- ProtectedSystem. Web. UI. WebControls. Button Button3;
- Private VoidPage_Load (ObjectSender, System. EventArgs e)
- {
- This. GetPostBackEventReference (This. Button3 );// Ensure that _ doPostBack (eventTarget, eventArgument) is correctly registered
- If(! IsPostBack)
- {
- System. Text. StringBuilder sb =NewSystem. Text. StringBuilder ();
- Sb. Append ("If (typeof (Page_ClientValidate) = 'function') {if (Page_ClientValidate () = false) {return false ;}}");// Verify the execution of the 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 click Event of the button is executed on the server side.
- Sb. Append (";");
- Button3.Attributes. Add ("Onclick", Sb. ToString ());
- }
- }
- # Region Web Form Designer generated code
- Override Protected VoidOnInit (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 VoidInitializeComponent ()
- {
- This. Button3.Click + =NewSystem. EventHandler (This. Button3_Click );
- This. Load + =NewSystem. EventHandler (This. Page_Load );
- }
- # Endregion
- Private VoidButton3_Click (ObjectSender, 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.
- ASP. NET Server Control Development-Composite Control
- Introduction to "three-layer structure" in ASP. NET
- 26 methods for optimizing ASP. NET performance
- Comparison of html controls and web controls in ASP. NET
- Object Description in ASP. NET