How to Prevent the page button from being submitted multiple times, and click submit on the page
Problem Background:
In the KPI classification rating assessment system at hand, the submit Button on the page is made with a LinkButton or Button. When a large number of users access the site online at the same time, the application server may experience a CPU usage of 100%, and the page will remain stuck. If the user is not clear, click the submit button to submit the site repeatedly, this results in a large amount of duplicate data in the database.
In fact, even if the server does not collapse and you click the submit button frequently, the problem of repeated submission may occur.
Tried: 1) set the Enabled attribute of the submit button to "Enabled = false" in the Click Event of the submit button. The attribute setting is invalid before the new page is obtained, and the problem persists;
2) set the disabled = true for the submit button in js in the client event. At this time, the server event of the submit button will not be executed;
3) I also tried to click the submit button and immediately bring up the div mask layer. The effect is not satisfactory and the problem persists;
4) add an HTML button, hide the submit button, and click the HTML button to submit. In the client event of the HTML button, make the HTML button unavailable (prevent repeated submission ), the server event that triggers the submit button. After the page is sent back, the HTML button automatically becomes available. This method is feasible. If there are deficiencies or better methods, I hope you will not be enlightened.
Solution:
1) In addition to the submit button LinkButton (ID: lbtSave), add an HTML button
<Input type = "button" id = "htmlSave" value = "Submit" onclick = "SingleSubmit ()"/>
2) Hide lbtSave. Note that you cannot hide lbtSave by setting its Visible attribute to False. Otherwise, lbtSave's server event lbtSave_Click cannot be triggered. a feasible method is to use <div style = "display: none; "> </div> contains lbtSave for hiding or directly using # lbtSave {display: none;} for hiding
3) Add the js Code in the
1 <script type="text/javascript">2 function SingleSubmit()3 {4 document.getElementById("htmlSave").disabled = true;5 document.getElementById("lbtSave").click();6 }7 </script>
4) Click htmlSave and execute the SingleSubmit () method to make htmlSave unavailable (prevent repeated submission) to trigger the lbtSave_Click event
5) after page sending back, that is, after the lbtSave_Click event is executed, htmlSave is automatically available.
To simulate real scenarios, add the Thread Sleep Thread. Sleep (5000) for 5s in the lbtSave_Click event );.