Prevent page from submit multiple times

xiaoxiao2021-03-14  196

The code supplied here is used to implement a button from a button in the ASP.NET page to remove all the Button in this page, thereby preventing the submission caused by the submission delay. Based on the previous overceclickButton script.

<

Script logage

=

"

JavaScript

"

>

FUNCTION

DisableThersubmit () {

VAR

Obj

=

Event.srcelement;

VAR

Objs

=

Document.getlementsBytagname ('Input');

for

(

VAR

i

=

0

I

<

Objs.length; i

) {

IF

(Objs [i] .type.tolowercase ()

==

'Submit') {OBJS [i] .disabled

=

True

}}}

//

->

Script

>

public

Class

PreventMultiick: 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);

//

Guarantee __dopostback (evenettarget, eventargument) correctly registration

IF

(

!

Ispostback) {system.text.stringbuilder SB

=

New

System.Text.StringBuilder (); sb.append (

"

IF (TypeOf (Page_ClientValidate) == 'function') {IF (Page_ClientValidate () == false) {Return False;}}

"

);

//

Ensure the execution of the verification function

Sb.append

"

IF (Window.Confirm ('Are you Sure?') == false) Return False;

"

);

//

Custom client script

Sb.append

"

DisableothersUBmit ();

"

);

//

Disable All Submit Button

Sb.append

THIS

.GetPostBackeventreference (

THIS

.Button3));

//

Submit using __dopostback to ensure that the button's server-side Click event is executed

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.

//

InitializationComponent ();

Base

.Onit (e);

///

///

Required Method for Designer Support - Do Not Modify

///

The Contents of this Method with the code editor.

///

Private

Void

InitializationComponent () {

THIS

.Button3.click

=

New

System.eventhandler

THIS

.Button3_click;

THIS

.Load

=

New

System.eventhandler

THIS

.Page_load);

#ndregion

Private

Void

Button3_click

Object

Sender, System.EventArgs E) {system.threading.thread.sleep

3000

); Response.write

"

Hello World!

"

}}

Here is just disable off all Submit Button, I think other possible controls can be used to disable by a similar approach.

转载请注明原文地址:https://www.9cbs.com/read-129429.html

New Post(0)