views:

252

answers:

2

I am trying to prevent users from double clicking on the submit button for a page I'm updating. The problem is that there is server side validation that has to be done to determine if the user has to do any updates before we can move on. I currently have the following code on my submit event for my form.

<asp:Button ID="SubmitPayment" runat="server" OnClientClick="this.disabled='true';" UseSubmitBehavior="false" OnClick="SubmitPayment_Click" Text="Submit" />

Where this becomes an issue is where the page does not pass validation. In this instance everything I have tried to enable the button has failed. It's hard for them to resubmit corrected information with the submit button disabled. I have tried both of the following methods at the end of my validation to re-enable it.

SubmitPayment.Enabled = true;
SubmitPayment.Attributes.Add("disabled", "false);

What must I do to re-enable this control? This is in Visual Studio 2005. Thanks in advance.

-edit- The approach that I used was as follows. I added an additional decoy button that was disabled and had the display css property set to none. I then used javascript that would hide the submit button and show the decoy button in the OnClientClick event. Finally, the end of the server side method would update the css properties on the buttons to hide and show them afterwards.

Code segments are as follows. Thanks again for the help

function PreventDoubleClick()
    {
        var sp = document.getElementById("SubmitPayment");
        var db = document.getElementById("DecoyButton");
        sp.style.display = "none";
        db.style.display = "inline";
    }

<asp:Button ID="SubmitPayment" runat="server" OnClientClick="javascript:PreventDoubleClick();" UseSubmitBehavior="false" OnClick="SubmitPayment_Click" Text="Submit" />
<asp:Button ID="DecoyButton" Enabled="false" runat="server" style="display:none;" Text="Please Wait..."/>

DecoyButton.Style.Add("display", "none");
SubmitPayment.Style.Add("display", "inline");
+1  A: 

I have had a similar problem before and the best solution I came up with was to hide the button and replace it with a please wait (or validating) message. If it fails validation you can then show the button again

jmein
Can't say it's my favorite approach, but it's the only thing I could find that worked. Thanks for the suggestion.
Phillip Benages
As it turns out, there is one other problem with the solution I added in my post. If run multiple times the decoy button will stay on the page permanently. Any ideas on how to resolve this?
Phillip Benages
A: 

I know this is a little late post but I had this issue recently and put together a few different posts to get my desired effect. Find it here http://trentkocurek.tumblr.com/post/435827507/aspdotnet-stop-double-clicking.

Trent