Galin Iliev's blog

Software Architecture & Development

Prevent multiple clicks on Submit button in ASP.NET

Recently I had to solve very common problem: When users what to submit the page by clicking on Submit button very often they become inpatient and click the button again which results in another button OnClick event firing (and if you save db record) duplicating records in database.

The most obvious solution is to use JavaScript to disable submit button. Unfortunately this easy solution is not the best because of number of reasons - see Andy Smit's blog entry you don't want to disable buttons after they are clicked here for more details.

So I decided to use another approach : I won't disable button with I will hide it and I show div element with text that would calm user down :). Thus buttons are visisble according ASP.NET but parent HTML element hides them :)

this is the aspx code that declares buttons

<div id="divButtons" style="display:inline;">
   <asp:Button ID="btnSubmit" runat="server" Text="Submit" CssClass="buttons" OnClientClick="SubmitButtonClicked();return true;" OnClick="btnSubmit_Click" style="padding-left: 10; padding-right: 10;"></asp:Button>


   <input type="button" value="Cancel" onclick="javascript:top.hidePopWin(false);" style="padding-left: 10; padding-right: 10;"/>



<div id="divWait" style="display:none;">Note is being saved. Please wait respond from server...</div>                    


thus asp:Buttons controls fires SubmitButtonClicked(); javascript function before post the form.

Here is the js code:

function SubmitButtonClicked()


    if (typeof(ValidatorOnSubmit) == "function"){

        if (Page_ClientValidate() == false) {

            return false; }}


    $get("divButtons").style.display = "none";

    $get("divWait").style.display = "";


UPDATE: The function above is edited according the link below and all validators works as expected. :) Thanks John!

Although the bug I think it is good starting point.

You can see here for alternative solution -

Comments (5) -

  • 翻译公司

    3/7/2007 8:01:03 AM | Reply

    Hello I like your page is interesting...
    10/325 - Vicoprofen - Lortab- Tylenol #3- - Ativan
    All Major Medications are available right here at:

  • 货架

    3/7/2007 8:03:13 AM | Reply

    In the same calification we can find drugs like!

  • 货架

    7/30/2007 6:20:33 AM | Reply

    Have a great day!