Tricky postback

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

    #1

    Tricky postback

    Hello,

    In an aspx page i have webform with some textboxes and a simple
    button. When the button is clicked, there is a postback and then the
    code in the click event of the button is executed.

    However in this code (click event of the button), i'm processing an
    online payment, which takes about 5 seconds. While waiting for the
    payment to be processed, the user can click again on the button, and
    this is what i want to block. I want to disable the button once
    clicked, and then execute the code for the web payment.

    However when we disable a button in the Load event, the page is only
    displayed after the Unload event, so the button still appears as
    enabled when executing the code in the click event of the button.

    I tried to call a javascript function on the onclick of the button to
    disable it but i get a compilation error at runtime. Is there a way to
    disable a webform button when clicked, then execute the code on the
    Click event of this button? The button needs to appear as disabled on
    the page before the code is executed.

    Thanks for any help!
  • Steve C. Orr, MCSD

    #2
    Re: Tricky postback

    Even if you disable the button you'll likely have the same problem if the
    person refreshes their browser.
    To solve this problem, you can generate a unique id for that web page
    instance.
    If you detect that unique id being posted more than once, then ignore the
    subsequent reposts.
    Here's a good article on the subject:


    --
    I hope this helps,
    Steve C. Orr, MCSD




    "Matt" <metal@rocks.co m> wrote in message
    news:sim5jvk0oe aidumhcs8hrsch9 gj1mj81rh@4ax.c om...[color=blue]
    > Hello,
    >
    > In an aspx page i have webform with some textboxes and a simple
    > button. When the button is clicked, there is a postback and then the
    > code in the click event of the button is executed.
    >
    > However in this code (click event of the button), i'm processing an
    > online payment, which takes about 5 seconds. While waiting for the
    > payment to be processed, the user can click again on the button, and
    > this is what i want to block. I want to disable the button once
    > clicked, and then execute the code for the web payment.
    >
    > However when we disable a button in the Load event, the page is only
    > displayed after the Unload event, so the button still appears as
    > enabled when executing the code in the click event of the button.
    >
    > I tried to call a javascript function on the onclick of the button to
    > disable it but i get a compilation error at runtime. Is there a way to
    > disable a webform button when clicked, then execute the code on the
    > Click event of this button? The button needs to appear as disabled on
    > the page before the code is executed.
    >
    > Thanks for any help![/color]


    Comment

    • eruess

      #3
      Re: Tricky postback

      I had this problem with an authentication page where authenticating the user
      took a few seconds and I didn't want them to keep clicking. Basically you
      have to do 2 things with 1 click... something to visually alter the screen,
      and then handle the actual click in your c/vb.net code.

      Make a javascript block to do whatever you need to do on the client when
      they click the button. In the example, js renders the button "hidden".

      <Script Language="JavaS cript">
      function clickHandler()
      {
      frmLogin.btnLog in.style.visibi lity = 'hidden';
      }
      </Script>

      In my html, here's the submit button the user clicks:

      <form ID="frmLogin" runat="server">
      <asp:Button ID="btnLogin" class="button" text="Log In"
      onclick="Login_ Click" Runat="server" />
      </form>

      Now in Sub page_load, you need a call to RegisterOnSubmi tStatement. This,
      afaik, tells asp.net to run the js function specified then handle the click
      event in asp.net:

      Sub Page_Load(s As Object, e As EventArgs)
      RegisterOnSubmi tStatement("sub mit", "clickHandler() ;")
      '...code

      So when the user clicks btnLogin on my form, RegisterOnSubmi tStatement calls
      the javascript that hides the button, and then my vb.net routine called
      "Login_Clic k" would run. 2 routines for the price of 1 click.

      You can augment the functionality of the clickHandler(); js routine to
      display a please wait message, etc. Just don't damage the integrity of the
      button object from the js code or the codebehind handling the button event
      may fail. For example, I believe this code breaks if you 'disable' the
      button or remove it completely. Hiding it is safe, and certainly renders
      the button un-clickable for the remainder of the page life.

      HTH


      "Matt" <metal@rocks.co m> wrote in message
      news:sim5jvk0oe aidumhcs8hrsch9 gj1mj81rh@4ax.c om...[color=blue]
      > Hello,
      >
      > In an aspx page i have webform with some textboxes and a simple
      > button. When the button is clicked, there is a postback and then the
      > code in the click event of the button is executed.
      >
      > However in this code (click event of the button), i'm processing an
      > online payment, which takes about 5 seconds. While waiting for the
      > payment to be processed, the user can click again on the button, and
      > this is what i want to block. I want to disable the button once
      > clicked, and then execute the code for the web payment.
      >
      > However when we disable a button in the Load event, the page is only
      > displayed after the Unload event, so the button still appears as
      > enabled when executing the code in the click event of the button.
      >
      > I tried to call a javascript function on the onclick of the button to
      > disable it but i get a compilation error at runtime. Is there a way to
      > disable a webform button when clicked, then execute the code on the
      > Click event of this button? The button needs to appear as disabled on
      > the page before the code is executed.
      >
      > Thanks for any help![/color]


      Comment

      • MS News \(MS ILM\)

        #4
        Re: Tricky postback

        I tried to run your code and I am getting errors
        'ASP.WebForm1_a spx' does not contain a definition for 'Login_Click'

        ???

        "eruess" <eruess@r.com > wrote in message
        news:PI6dncXcTY bddq-iRVn-hg@speakeasy.ne t...[color=blue]
        > I had this problem with an authentication page where authenticating the[/color]
        user[color=blue]
        > took a few seconds and I didn't want them to keep clicking. Basically you
        > have to do 2 things with 1 click... something to visually alter the[/color]
        screen,[color=blue]
        > and then handle the actual click in your c/vb.net code.
        >
        > Make a javascript block to do whatever you need to do on the client when
        > they click the button. In the example, js renders the button "hidden".
        >
        > <Script Language="JavaS cript">
        > function clickHandler()
        > {
        > frmLogin.btnLog in.style.visibi lity = 'hidden';
        > }
        > </Script>
        >
        > In my html, here's the submit button the user clicks:
        >
        > <form ID="frmLogin" runat="server">
        > <asp:Button ID="btnLogin" class="button" text="Log In"
        > onclick="Login_ Click" Runat="server" />
        > </form>
        >
        > Now in Sub page_load, you need a call to RegisterOnSubmi tStatement. This,
        > afaik, tells asp.net to run the js function specified then handle the[/color]
        click[color=blue]
        > event in asp.net:
        >
        > Sub Page_Load(s As Object, e As EventArgs)
        > RegisterOnSubmi tStatement("sub mit", "clickHandler() ;")
        > '...code
        >
        > So when the user clicks btnLogin on my form, RegisterOnSubmi tStatement[/color]
        calls[color=blue]
        > the javascript that hides the button, and then my vb.net routine called
        > "Login_Clic k" would run. 2 routines for the price of 1 click.
        >
        > You can augment the functionality of the clickHandler(); js routine to
        > display a please wait message, etc. Just don't damage the integrity of[/color]
        the[color=blue]
        > button object from the js code or the codebehind handling the button event
        > may fail. For example, I believe this code breaks if you 'disable' the
        > button or remove it completely. Hiding it is safe, and certainly renders
        > the button un-clickable for the remainder of the page life.
        >
        > HTH
        >
        >
        > "Matt" <metal@rocks.co m> wrote in message
        > news:sim5jvk0oe aidumhcs8hrsch9 gj1mj81rh@4ax.c om...[color=green]
        > > Hello,
        > >
        > > In an aspx page i have webform with some textboxes and a simple
        > > button. When the button is clicked, there is a postback and then the
        > > code in the click event of the button is executed.
        > >
        > > However in this code (click event of the button), i'm processing an
        > > online payment, which takes about 5 seconds. While waiting for the
        > > payment to be processed, the user can click again on the button, and
        > > this is what i want to block. I want to disable the button once
        > > clicked, and then execute the code for the web payment.
        > >
        > > However when we disable a button in the Load event, the page is only
        > > displayed after the Unload event, so the button still appears as
        > > enabled when executing the code in the click event of the button.
        > >
        > > I tried to call a javascript function on the onclick of the button to
        > > disable it but i get a compilation error at runtime. Is there a way to
        > > disable a webform button when clicked, then execute the code on the
        > > Click event of this button? The button needs to appear as disabled on
        > > the page before the code is executed.
        > >
        > > Thanks for any help![/color]
        >
        >[/color]


        Comment

        • MS News \(MS ILM\)

          #5
          Re: Tricky postback

          Got it. Sorry I did not provide the Login_Click Sub in code Behind

          "MS News (MS ILM)" <sql_agentman@h otmail.com> wrote in message
          news:ujSbfzdXDH A.1680@tk2msftn gp13.phx.gbl...[color=blue]
          > I tried to run your code and I am getting errors
          > 'ASP.WebForm1_a spx' does not contain a definition for 'Login_Click'
          >
          > ???
          >
          > "eruess" <eruess@r.com > wrote in message
          > news:PI6dncXcTY bddq-iRVn-hg@speakeasy.ne t...[color=green]
          > > I had this problem with an authentication page where authenticating the[/color]
          > user[color=green]
          > > took a few seconds and I didn't want them to keep clicking. Basically[/color][/color]
          you[color=blue][color=green]
          > > have to do 2 things with 1 click... something to visually alter the[/color]
          > screen,[color=green]
          > > and then handle the actual click in your c/vb.net code.
          > >
          > > Make a javascript block to do whatever you need to do on the client when
          > > they click the button. In the example, js renders the button "hidden".
          > >
          > > <Script Language="JavaS cript">
          > > function clickHandler()
          > > {
          > > frmLogin.btnLog in.style.visibi lity = 'hidden';
          > > }
          > > </Script>
          > >
          > > In my html, here's the submit button the user clicks:
          > >
          > > <form ID="frmLogin" runat="server">
          > > <asp:Button ID="btnLogin" class="button" text="Log In"
          > > onclick="Login_ Click" Runat="server" />
          > > </form>
          > >
          > > Now in Sub page_load, you need a call to RegisterOnSubmi tStatement.[/color][/color]
          This,[color=blue][color=green]
          > > afaik, tells asp.net to run the js function specified then handle the[/color]
          > click[color=green]
          > > event in asp.net:
          > >
          > > Sub Page_Load(s As Object, e As EventArgs)
          > > RegisterOnSubmi tStatement("sub mit", "clickHandler() ;")
          > > '...code
          > >
          > > So when the user clicks btnLogin on my form, RegisterOnSubmi tStatement[/color]
          > calls[color=green]
          > > the javascript that hides the button, and then my vb.net routine called
          > > "Login_Clic k" would run. 2 routines for the price of 1 click.
          > >
          > > You can augment the functionality of the clickHandler(); js routine to
          > > display a please wait message, etc. Just don't damage the integrity of[/color]
          > the[color=green]
          > > button object from the js code or the codebehind handling the button[/color][/color]
          event[color=blue][color=green]
          > > may fail. For example, I believe this code breaks if you 'disable' the
          > > button or remove it completely. Hiding it is safe, and certainly[/color][/color]
          renders[color=blue][color=green]
          > > the button un-clickable for the remainder of the page life.
          > >
          > > HTH
          > >
          > >
          > > "Matt" <metal@rocks.co m> wrote in message
          > > news:sim5jvk0oe aidumhcs8hrsch9 gj1mj81rh@4ax.c om...[color=darkred]
          > > > Hello,
          > > >
          > > > In an aspx page i have webform with some textboxes and a simple
          > > > button. When the button is clicked, there is a postback and then the
          > > > code in the click event of the button is executed.
          > > >
          > > > However in this code (click event of the button), i'm processing an
          > > > online payment, which takes about 5 seconds. While waiting for the
          > > > payment to be processed, the user can click again on the button, and
          > > > this is what i want to block. I want to disable the button once
          > > > clicked, and then execute the code for the web payment.
          > > >
          > > > However when we disable a button in the Load event, the page is only
          > > > displayed after the Unload event, so the button still appears as
          > > > enabled when executing the code in the click event of the button.
          > > >
          > > > I tried to call a javascript function on the onclick of the button to
          > > > disable it but i get a compilation error at runtime. Is there a way to
          > > > disable a webform button when clicked, then execute the code on the
          > > > Click event of this button? The button needs to appear as disabled on
          > > > the page before the code is executed.
          > > >
          > > > Thanks for any help![/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • eruess

            #6
            Re: Tricky postback

            Login_Click is the name of a Sub in my code. You'll need to modify my post
            to have it function within your own project.
            [color=blue][color=green]
            >>When the button is clicked, there is a postback and then the[/color][/color]
            code in the click event of the button is executed.
            However in this code (click event of the button), i'm processing an
            online payment, which takes about 5 seconds.<<

            So then instead of trying to call my Login_Click (which doesn't exist in
            your application) you'll want to call whatever sub does what you described
            in the above paragraph... 'Button1_Click' or whatever you / vs.net may have
            named it.

            Bear in mind with my project, Login_Click did not Handle any control events
            (such as clicking), and AutoEventWireUp was False. I have not tested this
            thing in a situation where I'm directly calling the sub that also handles
            the button's click.

            "MS News (MS ILM)" <sql_agentman@h otmail.com> wrote in message
            news:ujSbfzdXDH A.1680@tk2msftn gp13.phx.gbl...[color=blue]
            > I tried to run your code and I am getting errors
            > 'ASP.WebForm1_a spx' does not contain a definition for 'Login_Click'
            >
            > ???[/color]


            Comment

            • Matt

              #7
              Re: Tricky postback

              Thanks, this is exactly what i was looking for! I also added some code
              in the javascript function to show a layer, containing a message and
              an animated gif acting like a progress bar.

              However the gif stops when the web payment code is executed, so the
              gif is useless. A flash animation works but i don't want to use flash
              in this project.

              But the essential is that it works, thanks!



              On Thu, 7 Aug 2003 17:14:13 -0700, "eruess" <eruess@r.com > wrote:
              [color=blue]
              >I had this problem with an authentication page where authenticating the user
              >took a few seconds and I didn't want them to keep clicking. Basically you
              >have to do 2 things with 1 click... something to visually alter the screen,
              >and then handle the actual click in your c/vb.net code.
              >
              >Make a javascript block to do whatever you need to do on the client when
              >they click the button. In the example, js renders the button "hidden".
              >
              ><Script Language="JavaS cript">
              > function clickHandler()
              > {
              > frmLogin.btnLog in.style.visibi lity = 'hidden';
              > }
              ></Script>
              >
              >In my html, here's the submit button the user clicks:
              >
              ><form ID="frmLogin" runat="server">
              > <asp:Button ID="btnLogin" class="button" text="Log In"
              >onclick="Login _Click" Runat="server" />
              ></form>
              >
              >Now in Sub page_load, you need a call to RegisterOnSubmi tStatement. This,
              >afaik, tells asp.net to run the js function specified then handle the click
              >event in asp.net:
              >
              >Sub Page_Load(s As Object, e As EventArgs)
              > RegisterOnSubmi tStatement("sub mit", "clickHandler() ;")
              > '...code
              >
              >So when the user clicks btnLogin on my form, RegisterOnSubmi tStatement calls
              >the javascript that hides the button, and then my vb.net routine called
              >"Login_Click " would run. 2 routines for the price of 1 click.
              >
              >You can augment the functionality of the clickHandler(); js routine to
              >display a please wait message, etc. Just don't damage the integrity of the
              >button object from the js code or the codebehind handling the button event
              >may fail. For example, I believe this code breaks if you 'disable' the
              >button or remove it completely. Hiding it is safe, and certainly renders
              >the button un-clickable for the remainder of the page life.
              >
              >HTH
              >
              >
              >"Matt" <metal@rocks.co m> wrote in message
              >news:sim5jvk0o eaidumhcs8hrsch 9gj1mj81rh@4ax. com...[color=green]
              >> Hello,
              >>
              >> In an aspx page i have webform with some textboxes and a simple
              >> button. When the button is clicked, there is a postback and then the
              >> code in the click event of the button is executed.
              >>
              >> However in this code (click event of the button), i'm processing an
              >> online payment, which takes about 5 seconds. While waiting for the
              >> payment to be processed, the user can click again on the button, and
              >> this is what i want to block. I want to disable the button once
              >> clicked, and then execute the code for the web payment.
              >>
              >> However when we disable a button in the Load event, the page is only
              >> displayed after the Unload event, so the button still appears as
              >> enabled when executing the code in the click event of the button.
              >>
              >> I tried to call a javascript function on the onclick of the button to
              >> disable it but i get a compilation error at runtime. Is there a way to
              >> disable a webform button when clicked, then execute the code on the
              >> Click event of this button? The button needs to appear as disabled on
              >> the page before the code is executed.
              >>
              >> Thanks for any help![/color]
              >[/color]

              Comment

              • MS News \(MS ILM\)

                #8
                Re: Tricky postback

                Thank you, that is great

                "eruess" <eruess@r.com > wrote in message
                news:NOCdnXbVIP eaaq6iRVn-iA@speakeasy.ne t...[color=blue]
                > Login_Click is the name of a Sub in my code. You'll need to modify my[/color]
                post[color=blue]
                > to have it function within your own project.
                >[color=green][color=darkred]
                > >>When the button is clicked, there is a postback and then the[/color][/color]
                > code in the click event of the button is executed.
                > However in this code (click event of the button), i'm processing an
                > online payment, which takes about 5 seconds.<<
                >
                > So then instead of trying to call my Login_Click (which doesn't exist in
                > your application) you'll want to call whatever sub does what you described
                > in the above paragraph... 'Button1_Click' or whatever you / vs.net may[/color]
                have[color=blue]
                > named it.
                >
                > Bear in mind with my project, Login_Click did not Handle any control[/color]
                events[color=blue]
                > (such as clicking), and AutoEventWireUp was False. I have not tested this
                > thing in a situation where I'm directly calling the sub that also handles
                > the button's click.
                >
                > "MS News (MS ILM)" <sql_agentman@h otmail.com> wrote in message
                > news:ujSbfzdXDH A.1680@tk2msftn gp13.phx.gbl...[color=green]
                > > I tried to run your code and I am getting errors
                > > 'ASP.WebForm1_a spx' does not contain a definition for 'Login_Click'
                > >
                > > ???[/color]
                >
                >[/color]


                Comment

                Working...