How to prevent page buttons from being submitted multiple times in asp.net

Source: Internet
Author: User

Problem background:

On-Hand KPI classification rating system, the page's Submit button is made with LinkButton or button. When a large number of users at the same time online access to the site, the application server CPU occupied 100% of the bad situation, the page will not move, the user unknown continuous Click submit button repeated submission, resulting in a large number of data duplication in the database.

In fact, even if the server did not collapse, quickly and frequently click the Submit button, there will be repeated submission of the problem.

Tried: 1 to set the enabled attribute of the Submit button in the Click event of the Submit button Enabled = FALSE; , this property is not valid until the new page is taken, and the problem persists;

2 in the client event JS set the Submit button disabled disabled = TRUE; , the service-side event for the submit button will no longer execute;

3 also tried to click the Submit button immediately after the pop-up Div mask layer, the effect is not ideal, the problem still exists;

4 adds an HTML button, and hides the submit button, clicks the HTML button to submit, makes the HTML button unavailable in the client event of the HTML button (prevents duplicate submissions), triggers the server event for the Submit button, and the HTML button automatically becomes available after the page postback. This method is feasible, if there are deficiencies or better methods, but also hope that we do not hesitate to enlighten.

Solution Idea:

1 In addition to the Submit button LinkButton (ID is lbtsave), add an HTML button

<input type= "button" id= "Htmlsave" value= "Submit" onclick= "Singlesubmit ()"/>

2) Hide Lbtsave, note that can not set the Lbtsave Visible property is false to achieve hidden, otherwise Lbtsave server event Lbtsave_click will not be triggered; possible way: Use <div style= "display : none; " ></div> contains lbtsave to implement hidden or directly with #lbtSave {Display:none;}

3)

<script type= "Text/javascript" >

Functionsinglesubmit ()

{

document.getElementById ("Htmlsave"). Disabled =true;

document.getElementById ("Lbtsave"). Click ();

}

</script>

4) Click Htmlsave, execute Singlesubmit () method, make Htmlsave unavailable (prevent duplicate commit), trigger Lbtsave_click Event

5 after the page postback, that is, after the Lbtsave_click event is executed, the htmlsave automatically becomes available.

In order to simulate the real situation, 5s thread dormancy Thread.Sleep (5000) was added to the Lbtsave_click event;.

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.