Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Postback twice for a button click?

Postback twice for a button click?

Scheduled Pinned Locked Moved ASP.NET
debuggingcsharpasp-nethelptutorial
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pedestrian797
    wrote on last edited by
    #1

    I have a simple VB ASP.NET 2.0 page with a Button and a Label. The Label text is "0". For each click of the button (btnAdd), it should increment the Label text by 1. The code: Protected Sub btnAdd_Click(...) Handles btnAdd.Click Trace.Warn("Before add: " & lblCounter.Text) lblCounter.Text = (Int32.Parse(lblCounter.Text) + 1).ToString Trace.Warn("After add: " & lblCounter.Text) End Sub However, each time I click the button, the label always increase by 2 instead of the expected 1. What's the problem area? I tried to debug using Trace. I get the following result from the trace: Begin Raise PostBackEvent Before add: 0 After add: 1 Before add: 1 After add: 2 End Raise PostBackEvent Is this signifies PostBack event is being run twice per button click? How to solve it? Thanks for your assistance. ;)

    Pedestrian, Penang.

    L M P 3 Replies Last reply
    0
    • P pedestrian797

      I have a simple VB ASP.NET 2.0 page with a Button and a Label. The Label text is "0". For each click of the button (btnAdd), it should increment the Label text by 1. The code: Protected Sub btnAdd_Click(...) Handles btnAdd.Click Trace.Warn("Before add: " & lblCounter.Text) lblCounter.Text = (Int32.Parse(lblCounter.Text) + 1).ToString Trace.Warn("After add: " & lblCounter.Text) End Sub However, each time I click the button, the label always increase by 2 instead of the expected 1. What's the problem area? I tried to debug using Trace. I get the following result from the trace: Begin Raise PostBackEvent Before add: 0 After add: 1 Before add: 1 After add: 2 End Raise PostBackEvent Is this signifies PostBack event is being run twice per button click? How to solve it? Thanks for your assistance. ;)

      Pedestrian, Penang.

      L Offline
      L Offline
      lavanya_satheesh
      wrote on last edited by
      #2

      hi, i tried the same code out. i didnt get any probs as u mention. my code is here. Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Label1.Text = Val(Label1.Text) + 1 Label1.Text = (Int32.Parse(Label1.Text) + 1).ToString End Sub c there is no difference. but i am not having any probs. the out put is first 1 then 2 then 3 etc. i am not getting any result incremented by 2. c if u have all the property values correct. love, lavanya

      P 1 Reply Last reply
      0
      • P pedestrian797

        I have a simple VB ASP.NET 2.0 page with a Button and a Label. The Label text is "0". For each click of the button (btnAdd), it should increment the Label text by 1. The code: Protected Sub btnAdd_Click(...) Handles btnAdd.Click Trace.Warn("Before add: " & lblCounter.Text) lblCounter.Text = (Int32.Parse(lblCounter.Text) + 1).ToString Trace.Warn("After add: " & lblCounter.Text) End Sub However, each time I click the button, the label always increase by 2 instead of the expected 1. What's the problem area? I tried to debug using Trace. I get the following result from the trace: Begin Raise PostBackEvent Before add: 0 After add: 1 Before add: 1 After add: 2 End Raise PostBackEvent Is this signifies PostBack event is being run twice per button click? How to solve it? Thanks for your assistance. ;)

        Pedestrian, Penang.

        M Offline
        M Offline
        munklefish
        wrote on last edited by
        #3

        Hi, I've had similar problems in the past with updating data. Its not a 'problem' as such that can be solved and sounds more like a case of how and when you are binding data / incrementing the values. In most cases it is to do with the fact that you're increment code is being called twice. How and when this occurrs i couldnt tell you because it is of course specific to your page / code. The simplest - although perhaps most time consuming solution - is to rebuild the page from scratch. Implement the incremental code at the earliest of opportunities whilst there is minimal additional code associated with the page. This will make it much easier to work out exactly what is going on. Hope this helps.

        P 1 Reply Last reply
        0
        • P pedestrian797

          I have a simple VB ASP.NET 2.0 page with a Button and a Label. The Label text is "0". For each click of the button (btnAdd), it should increment the Label text by 1. The code: Protected Sub btnAdd_Click(...) Handles btnAdd.Click Trace.Warn("Before add: " & lblCounter.Text) lblCounter.Text = (Int32.Parse(lblCounter.Text) + 1).ToString Trace.Warn("After add: " & lblCounter.Text) End Sub However, each time I click the button, the label always increase by 2 instead of the expected 1. What's the problem area? I tried to debug using Trace. I get the following result from the trace: Begin Raise PostBackEvent Before add: 0 After add: 1 Before add: 1 After add: 2 End Raise PostBackEvent Is this signifies PostBack event is being run twice per button click? How to solve it? Thanks for your assistance. ;)

          Pedestrian, Penang.

          P Offline
          P Offline
          Paddy Boyd
          wrote on last edited by
          #4

          I'd also make sure that there isn't another delegate registered on the page for that event, could force it to call twice.

          P 1 Reply Last reply
          0
          • L lavanya_satheesh

            hi, i tried the same code out. i didnt get any probs as u mention. my code is here. Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Label1.Text = Val(Label1.Text) + 1 Label1.Text = (Int32.Parse(Label1.Text) + 1).ToString End Sub c there is no difference. but i am not having any probs. the out put is first 1 then 2 then 3 etc. i am not getting any result incremented by 2. c if u have all the property values correct. love, lavanya

            P Offline
            P Offline
            pedestrian797
            wrote on last edited by
            #5

            Thanks very much for your help.

            Pedestrian, Penang.

            1 Reply Last reply
            0
            • M munklefish

              Hi, I've had similar problems in the past with updating data. Its not a 'problem' as such that can be solved and sounds more like a case of how and when you are binding data / incrementing the values. In most cases it is to do with the fact that you're increment code is being called twice. How and when this occurrs i couldnt tell you because it is of course specific to your page / code. The simplest - although perhaps most time consuming solution - is to rebuild the page from scratch. Implement the incremental code at the earliest of opportunities whilst there is minimal additional code associated with the page. This will make it much easier to work out exactly what is going on. Hope this helps.

              P Offline
              P Offline
              pedestrian797
              wrote on last edited by
              #6

              Thanks for your help.

              Pedestrian, Penang.

              1 Reply Last reply
              0
              • P Paddy Boyd

                I'd also make sure that there isn't another delegate registered on the page for that event, could force it to call twice.

                P Offline
                P Offline
                pedestrian797
                wrote on last edited by
                #7

                Thanks.

                Pedestrian, Penang.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups