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

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
 
G

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

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
 
H

Hillbilly

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

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
 
A

AAaron123

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
 
G

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?

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,833
Latest member
BettyeMacf

Latest Threads

Top