I have a webPage that has a timer on it. When this timer runs it updates a text field on a container on that webPage. The timer is set to multiple and 1000 milliseconds. I would expect my code that is just a simple add one every time it runs to count upward starting at 1.
However, it hits one and doesnt update again. Is this a problem with the timer? the fact its trying to run on the container multiple times? or ???
Var count as integer
count = count + 1
webPage.container1.Label1.Text = count.ToString
If this is the code in the method called when the timer interval is reached, then count will always be 1, because each time the method runs:
- variable count is instantiated with a value of 0
- 1 is added to it
- when the method exits variable count is destructed
For count to retain its value, you need to make it a property of the WebPage.
1000 ms is a very short period of time, meaning that the WebApp will need to update the browser every second, that will keep the app very busy.
Great Catch. This was a simplified version of what I am actually doing but it was extremely helpful. Thank you!
He could also declare count as static
Static Count as Integer
Using a static, the value would be shared across all sessions. Best not to introduce that here.