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

  • Thread starter Thread starter AAaron123
  • Start date Start date
A

AAaron123

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
 
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
 
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?

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
 
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
 
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
 
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".
 
Back
Top