Preventing button code being run twice

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

I have a v2.0 site that has a form with a GO button which runs another
application and then returns some data which is then processed and then I
issue a response.redirect to another form to display the returned data.

My problem is that it is possible for a user to click the button several
times causing the external app to run several times.

My first thought was to set the button.enabled = false as soon as it is
clicked but that does not work, presumably because of caching.

What is the best way to stop this code executing more than once or until
the page is opened again?

Thanks

Bill
 
Can you set the caption of the button to something like "Processing..."
when it's clicked?

Then when the user clicks the button if it equals "Processing..." do
nothing.
 
Otherwise, you could just disable the button after it has been clicked.
Use a variable that would change if the button had been clicked. Then
if you needed the user to be able to click that same button again
later, have another variable that would re-enable.
 
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Response.Write("Write this line once!")
Button1.Attributes.Add("onClick", _
"document.forms[0]." & Button1.UniqueID & ".disabled =
true;")
End Sub
 
Back
Top