Postback twice for a button click?
-
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.
-
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.
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
-
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.
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.
-
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.
I'd also make sure that there isn't another delegate registered on the page for that event, could force it to call twice.
-
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
Thanks very much for your help.
Pedestrian, Penang.
-
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.
Thanks for your help.
Pedestrian, Penang.
-
I'd also make sure that there isn't another delegate registered on the page for that event, could force it to call twice.
Thanks.
Pedestrian, Penang.