Click to See Complete Forum and Search --> : Variable problem


Troy Erickson
April 30th, 2003, 11:11 AM
I have a class and in the class I declared a variable public. In the page load event I set the variable to a value. When a user presses a button I reference the variable. For some reason that variable always loses its value. Why??????

Public Class Motion
public NextOne as integer

Private Sub Page_Load
NextOne = 4
End Sub

Private Sub OnButton
dim i as integer
i = NextOne
End Sub

End class

This is a very rough layout that I am doing. I trace through pageload and nextone is equal 4 but as soon as onbutton is called it changes to zero.

DSJ
April 30th, 2003, 03:07 PM
I assume your talking about a web page. If so you need to realize that the variables you're defining only "live" while the server is processing the page. Once it is sent to the client, it no longer exsists on the server. To do what you're trying to do, you'll need to put the value on a hidden control on the webpage and set it's EnableViewState property to true.

Troy Erickson
May 1st, 2003, 08:36 AM
This is my first project assigned for the web. This was frustrating me to no end.