Home All Groups Group Topic Archive Search About

Preventing button code being run twice

Author
16 Aug 2006 4:29 PM
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

Author
16 Aug 2006 4:40 PM
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.


Bill wrote:
Show quoteHide quote
> 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
Author
16 Aug 2006 5:58 PM
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.

Bill wrote:
Show quoteHide quote
> 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
Author
17 Aug 2006 9:10 AM
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


Bill wrote:
Show quoteHide quote
> 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