Home > Uncategorized > How to prevent users from multiple submissions

How to prevent users from multiple submissions

I have been repeatedly asked about how to prevent users from clicking submit button more than once. If you have ever faced such a problem, you would probably know that there are many ways suggested by folks to handle this, things like using two buttons, disabling submit button using JavaScript and so on. Regrettably I never did find anything that worked like they said it would and more importantly some of those methods causes your server side events not to fire. The way I deal with this issue is not just disabling the button by greying it out, but not letting the form to be posted back using the code below:
1) Put this in between the HEAD tags of your page:


  <SCRIPT language=javascript>
     var isSubmittedFlag= false;


2) Add the following java script code to the button attributes collection in  Page_Load() event of your page

btnSubmit.Attributes.Add(“onclick”, “javascript:if(isSubmittedFlag){alert(‘Your first request is still being processed’);return false;}else{isSubmittedFlag=true;return true;}”)

Categories: Uncategorized Tags:
  1. No comments yet.
You must be logged in to post a comment.