Ajax prevents users from submitting 2 of solutions over and over again

Source: Internet
Author: User

The submission of the situation of friends can refer to, I hope to help you

 

The method can be loaded on the server side:

Copy Code code as follows:


private void onloading ()


{


System.Text.StringBuilder sb = new System.Text.StringBuilder ();


sb. Append ("function pageload () {var manager = Sys.WebForms.PageRequestManager.getInstance ();");


sb. Append ("Manager.add_beginrequest" (onbeginrequest); Manager.add_endrequest (Onendrequest)} var Lcpostbackelementid; ");


sb. Append ("function OnBeginRequest" (sender, args) {Lcpostbackelementid = Args.get_postbackelement (). Id.tolowercase (); if (Lcpostbackelementid = = "Btnadwords") {$get ("btnadwords"). Disabled = true; $get ("Btnadwords"). Value= ' Submitting ... '} ");


sb. Append ("function Onendrequest" (sender, args) {if (Lcpostbackelementid = = "Btnadwords") {$get ("btnadwords"). Disabled = False $get ("Btnadwords"). value= ' OK ';} ");





Scriptmanager.registerstartupscript (Page, Page.gettype (), "Btnadwords", sb. ToString (), true);


}


can also be written directly in the page script:

Copy Code code as follows:


<script>


function pageload ()


{


var manager = Sys.WebForms.PageRequestManager.getInstance ();


manager.add_beginrequest (onbeginrequest);


manager.add_endrequest (onendrequest)


}


var Lcpostbackelementid;


function OnBeginRequest (sender, args)


{


Lcpostbackelementid = Args.get_postbackelement (). Id.tolowercase ();


if (Lcpostbackelementid = = ' Btnadwords ')


{


$get (' btnadwords '). Disabled = true;


$get (' btnadwords '). Value= ' is submitting ... ';


}


}


function Onendrequest (sender, args)


{


if (Lcpostbackelementid = = "Btnadwords")


{


$get (' btnadwords '). Disabled = false;


$get (' btnadwords '). value= ' OK ';


}


}


</script>


For more information please refer to: http://msdn.microsoft.com/zh-cn/magazine/cc163319.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.