SoFunction
Updated on 2025-03-04

Solution to block page buttons multiple submissions

Question background:

The KPI classification rating assessment system on hand, the page submission button is made using LinkButton or Button. When a large number of users access the site online at the same time, the application server has a bad situation of 100% CPU occupancy, the page will be stuck, and the user will click the submit button to submit repeatedly in an unknown situation, causing a large amount of duplicate data to appear in the database.

In fact, even if the server does not crash and you quickly and frequently click the submit button, there will be a problem of repeated submissions.

Try: 1) Set the Enabled property of the Submit button in the click event of the Submit buttonEnabled = false; , This property setting is invalid before the new page is obtained, and the problem still exists;

2) Set the submit button in the client eventdisabled disabled = true; , the server event that submits the button will no longer be executed;

3) I also tried to pop up the div mask layer immediately after clicking the submit button. The effect was not ideal, and the problem still exists;

4) Add an HTML button and hide the submit button. Click the HTML button to submit. Make the HTML button unavailable in the client event of the HTML button (block duplicate submissions), and then trigger the server event of the submit button. After the page is posted back, the HTML button will automatically become available. This method is feasible. If there are any shortcomings or better methods, I hope everyone will give me some advice.

Solution:

1) In addition to the submit button LinkButton (ID is lbtSave), add an HTML button

<input type="button"  value="submit" onclick="SingleSubmit()" />

2) Hide lbtSave. Note that you cannot set the Visible property of lbtSave to False to hide, otherwise the server event lbtSave_Click of lbtSave will not be triggered; feasible method: use <div style="display:none;"></div> to include lbtSave to hide or directly use #lbtSave{display:none;} to hide

3) Added js code to the <head></head> tag, as follows:

 <script type="text/javascript">
   function SingleSubmit()
   {
     ("htmlSave").disabled = true;
     ("lbtSave").click();
   }
 </script>

4) Click htmlSave, execute the SingleSubmit() method, make htmlSave unavailable (block duplicate submissions), and trigger the lbtSave_Click event

5) After the page is posted back, that is, after the lbtSave_Click event is executed, htmlSave will automatically become available.

To simulate the real scenario, add 5s of thread sleep (5000); in the lbtSave_Click event.

The above is the solution to the blocking page button that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!