0

I have a form with a submit button which I want to disable upon submitting (so the user does not submit the form content twice).

The form has 2 mandatory fields that should be filled in, so an easy on click disable button (client-side) will not do the trick i'm afraid.

Protected Sub Btn_SubmitContact_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Btn_SubmitContact.Click
     If Page.IsValid Then
          Btn_SubmitContact.Enabled = False
          //all other logic
     End If
 End Sub

This does not change the attribute of the key, the user can still click the button and post the content twice. I understand that some refresh/update needs to happen for the button to change...

Can someone please explain me how this works?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
rwinner
  • 348
  • 3
  • 6
  • 15
  • you can eritr js method that on form submit or button click disable that button – Ehsan Sajjad Apr 11 '14 at 11:33
  • You could handle the form-submit event to disable the button there if validation was successful. You could use jQuery: http://stackoverflow.com/q/7382849/284240 – Tim Schmelter Apr 11 '14 at 11:34

1 Answers1

1

First check the mandatory fields with asp:RequiredFieldValidator and then when the button is clicked you can disable it with Javascript:

<asp:button id="Btn_SubmitContact" 
        OnClientClick="this.disabled = true; this.value = 'In process...';"
        UseSubmitBehavior="false" OnClick="Btn_SubmitContact_Click"
        Text="Submit" runat="server" />
Cerveser
  • 752
  • 8
  • 23