Preventing button code being run twice

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill

    #1

    Preventing button code being run twice

    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.redire ct 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


  • Izzy

    #2
    Re: Preventing button code being run twice

    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:
    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.redire ct 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

    Comment

    • JoeW

      #3
      Re: Preventing button code being run twice

      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:
      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.redire ct 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

      Comment

      • Tips

        #4
        Re: Preventing button code being run twice

        Private Sub Button1_Click(B yVal sender As Object, ByVal e As
        System.EventArg s) Handles Button1.Click
        Response.Write( "Write this line once!")
        Button1.Attribu tes.Add("onClic k", _
        "document.f orms[0]." & Button1.UniqueI D & ".disabled =
        true;")
        End Sub


        Bill wrote:
        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.redire ct 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

        Comment

        Working...