P
pedestrian via DotNetMonster.com
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.
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.