CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2002
    Posts
    55

    Variable problem

    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.

  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868
    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.

  3. #3
    Join Date
    Feb 2002
    Posts
    55

    Thanks

    This is my first project assigned for the web. This was frustrating me to no end.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured