Link to home
Start Free TrialLog in
Avatar of RobertNZana
RobertNZanaFlag for United States of America

asked on

How prevent user clicking PAY twice?

I have a "pay now" button on my aspx page. I would like to prevent the users from clicking on the "pay now" button twice. Any ideas?

I was thinking of creating of creating a "please wait" modal message while it's processing. Or if you have further suggestions please let me know. Please post full code samples.

AJAX is ok to use too...
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Use OnClientClick to add a button.Enabled = False in the javascript
SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RobertNZana

ASKER

can u please post code sample?
Here you go



<script>
   function DisableButton(b)
   {
      b.disabled = true;
      b.value = 'Submitting';
      b.form.submit();
   }
</script>

<p>
   Click the button to see how it can be disabled and
   have its text changed when clicked...
</p>

<p>
   <input type="submit" name="SubmitButton" id="SubmitButton"
          value="Submit"
          onclick="DisableButton(this);" />
</p>

Open in new window

I could still click it twice.
Show us the code.
Avatar of Rick
Rick

... Or redirect to another page after payment is validated and verified.
How do I run the code in this sub after running the javascript?

Protected Sub cmdPay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdPay.Click

   <script type="text/javascript">
   function DisableButton(b)
   {
      b.disabled = true;
      b.value = 'Submitting';
      b.form.submit();
   }
    </script>
        <asp:Button ID="cmdPay" runat="server" Text="Submit Payment" onclientclick="DisableButton(this);" class="pay_button" />

Open in new window

I use this in all my pages
Only works on asp:button
<asp:Button runat="server" ID="btn_inc_save" Text="Save" OnClientClick="this.disabled = true; this.value = 'Submitting...';" UseSubmitBehavior="false" />

Open in new window

Does this work with the postback code too?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dint u find the above useful/working?
Yes basically. But, if there's a validation error (such as a bad email format input) now the button is disabled and I can't click it. Any work around for this? How can I check if the page is valid before disabling the button?
This seems to work. Thanks...

<asp:Button ID="cmdPay" runat="server" Text="Submit Payment" class="pay_button"
         OnClientClick="if(Page_ClientValidate()){this.disabled = true; this.value = 'Submitting...';}else{alert('Form is incomplete.');}" UseSubmitBehavior="false" />