How to make a variable with a value that persists over multiple postbacks

Discussion in 'ASP .Net' started by AAaron123, Apr 14, 2009.

  1. AAaron123

    AAaron123 Guest

    This is what I observer:
    On one postback I set a variable to 2
    On the next postback it has the valve of 0

    I know I could use a Session Variable to hold the value but that seems like
    an overkill.
    What is the simplest way to make a variable with a value that persists over
    multiple postbacks?

    Thanks
     
    AAaron123, Apr 14, 2009
    #1
    1. Advertising

  2. Re: How to make a variable with a value that persists over multiplepostbacks

    On Apr 14, 8:43 am, "AAaron123" <> wrote:
    > This is what I observer:
    > On one postback I set a variable to 2
    > On the next postback it has the valve of 0
    >
    > I know I could use a Session Variable to hold the value but that seems like
    > an overkill.
    > What is the simplest way to make a variable with a value that persists over
    > multiple postbacks?
    >
    > Thanks


    Hi Aaron,

    use the ViewState Property which is designed to keep values across
    postbacks
    More at: http://msdn.microsoft.com/en-us/library/ms972976.aspx

    Hope this helps
     
    Alexey Smirnov, Apr 14, 2009
    #2
    1. Advertising

  3. AAaron123

    Hillbilly Guest

    Generally speaking, I'd rather use the Session and put it into memory rather
    than drag it back and forth in the ViewState or how about using a hidden
    form element as another choice given the context of the data?

    "Alexey Smirnov" <> wrote in message
    news:...
    On Apr 14, 8:43 am, "AAaron123" <> wrote:
    > This is what I observer:
    > On one postback I set a variable to 2
    > On the next postback it has the valve of 0
    >
    > I know I could use a Session Variable to hold the value but that seems
    > like
    > an overkill.
    > What is the simplest way to make a variable with a value that persists
    > over
    > multiple postbacks?
    >
    > Thanks


    Hi Aaron,

    use the ViewState Property which is designed to keep values across
    postbacks
    More at: http://msdn.microsoft.com/en-us/library/ms972976.aspx

    Hope this helps
     
    Hillbilly, Apr 14, 2009
    #3
  4. AAaron123

    AAaron123 Guest

    "Alexey Smirnov" <> wrote in message
    news:...
    On Apr 14, 8:43 am, "AAaron123" <> wrote:
    > This is what I observer:
    > On one postback I set a variable to 2
    > On the next postback it has the valve of 0
    >
    > I know I could use a Session Variable to hold the value but that seems
    > like
    > an overkill.
    > What is the simplest way to make a variable with a value that persists
    > over
    > multiple postbacks?
    >
    > Thanks


    Hi Aaron,

    use the ViewState Property which is designed to keep values across
    postbacks
    More at: http://msdn.microsoft.com/en-us/library/ms972976.aspx

    Hope this helps


    That's a great article.
    I read about 1/3 of it and then jumped to what need now.
    I'm going to chip away at that until I've read it all a couple of times.

    Thanks
     
    AAaron123, Apr 14, 2009
    #4
  5. AAaron123

    AAaron123 Guest

    Well now at least I know how to use the ViewState.
    Session variable stays in the host's memory.
    It's never sent to the browser?


    Thanks


    "Hillbilly" <> wrote in message
    news:...
    > Generally speaking, I'd rather use the Session and put it into memory
    > rather than drag it back and forth in the ViewState or how about using a
    > hidden form element as another choice given the context of the data?
    >
    > "Alexey Smirnov" <> wrote in message
    > news:...
    > On Apr 14, 8:43 am, "AAaron123" <> wrote:
    >> This is what I observer:
    >> On one postback I set a variable to 2
    >> On the next postback it has the valve of 0
    >>
    >> I know I could use a Session Variable to hold the value but that seems
    >> like
    >> an overkill.
    >> What is the simplest way to make a variable with a value that persists
    >> over
    >> multiple postbacks?
    >>
    >> Thanks

    >
    > Hi Aaron,
    >
    > use the ViewState Property which is designed to keep values across
    > postbacks
    > More at: http://msdn.microsoft.com/en-us/library/ms972976.aspx
    >
    > Hope this helps
     
    AAaron123, Apr 14, 2009
    #5
  6. Re: How to make a variable with a value that persists over multiplepostbacks

    On 14 Apr., 16:09, "Hillbilly" <> wrote:
    > Generally speaking, I'd rather use the Session and put it into memory rather
    > than drag it back and forth in the ViewState or how about using a hidden
    > form element as another choice given the context of the data?
    >


    Why to put it into memory when you need it on one page only?
    The view state is placed in a hidden form field named "__VIEWSTATE".
     
    Alexey Smirnov, Apr 14, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maury
    Replies:
    3
    Views:
    2,123
  2. Jeremy Chapman

    Override how a data type persists

    Jeremy Chapman, Mar 21, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    301
    Jeremy Chapman
    Mar 21, 2006
  3. Replies:
    2
    Views:
    3,572
    Larry
    Jul 19, 2006
  4. Replies:
    0
    Views:
    480
  5. ses
    Replies:
    1
    Views:
    453
    Arved Sandstrom
    Apr 14, 2011
Loading...

Share This Page