Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

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...
0
RobertNZana
Asked:
RobertNZana
  • 7
  • 5
  • 3
  • +1
2 Solutions
 
CodeCruiserCommented:
Use OnClientClick to add a button.Enabled = False in the javascript
0
 
RobertNZanaAuthor Commented:
can u please post code sample?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
CodeCruiserCommented:
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

0
 
RobertNZanaAuthor Commented:
I could still click it twice.
0
 
CodeCruiserCommented:
Show us the code.
0
 
RickCommented:
... Or redirect to another page after payment is validated and verified.
0
 
RobertNZanaAuthor Commented:
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

0
 
RobertNZanaAuthor Commented:
   <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

0
 
abhinaypCommented:
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

0
 
RobertNZanaAuthor Commented:
Does this work with the postback code too?
0
 
abhinaypCommented:
yes..

<asp:Button runat="server" ID="btn_inc_save" Text="Save" OnClientClick="this.disabled = true; this.value = 'Submitting...';" UseSubmitBehavior="false" />

Protected Sub btn_inc_save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_inc_save.Click
        lbl_inc_error.Text = ValidateIncome()
        If (lbl_inc_error.Text = "") Then
            Dim objIncome As New FinancialIncome
            
            objIncome.JobTitle = txt_inc_job.Text
            objIncome.Address = txt_inc_street_address.Text
            objIncome.City = txt_inc_city.Text
            objIncome.State = txt_inc_state.Text
            objIncome.Zip = txt_inc_zip.Text
            objIncome.PhoneNumber = txt_inc_ph_no.Text
            objIncome.IncomeTypeID = ddl_inc_income_type.SelectedValue
            objIncome.AddNew()
            ClearIncome()
            EnableIncome(False)
        End If
    End Sub

Open in new window

0
 
abhinaypCommented:
Dint u find the above useful/working?
0
 
RobertNZanaAuthor Commented:
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?
0
 
RobertNZanaAuthor Commented:
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" />
       
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now