Preventing button code being run twice

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
 
I

Izzy

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.
 
J

JoeW

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.
 
T

Tips

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top