RobertNZana
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...
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...
Use OnClientClick to add a button.Enabled = False in the javascript
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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>
ASKER
I could still click it twice.
Show us the code.
... Or redirect to another page after payment is validated and verified.
ASKER
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
Protected Sub cmdPay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdPay.Click
ASKER
<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" />
Calling server side method from script
http://decoding.wordpress.com/2008/11/14/aspnet-how-to-call-a-server-side-method-from-client-side-javascript/
http://decoding.wordpress.com/2008/11/14/aspnet-how-to-call-a-server-side-method-from-client-side-javascript/
I use this in all my pages
Only works on asp:button
Only works on asp:button
<asp:Button runat="server" ID="btn_inc_save" Text="Save" OnClientClick="this.disabled = true; this.value = 'Submitting...';" UseSubmitBehavior="false" />
ASKER
Does this work with the postback code too?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dint u find the above useful/working?
ASKER
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?
ASKER
This seems to work. Thanks...
<asp:Button ID="cmdPay" runat="server" Text="Submit Payment" class="pay_button"
OnClientClick="if(Page_Cli entValidat e()){this. disabled = true; this.value = 'Submitting...';}else{aler t('Form is incomplete.');}" UseSubmitBehavior="false" />
<asp:Button ID="cmdPay" runat="server" Text="Submit Payment" class="pay_button"
OnClientClick="if(Page_Cli