Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to make a variable with a value that persists over multiple postbacks

Reply
Thread Tools

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

 
 
AAaron123
Guest
Posts: n/a
 
      04-14-2009
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


 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      04-14-2009
On Apr 14, 8:43*am, "AAaron123" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Hillbilly
Guest
Posts: n/a
 
      04-14-2009
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Apr 14, 8:43 am, "AAaron123" <(E-Mail Removed)> 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

 
Reply With Quote
 
AAaron123
Guest
Posts: n/a
 
      04-14-2009

"Alexey Smirnov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Apr 14, 8:43 am, "AAaron123" <(E-Mail Removed)> 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


 
Reply With Quote
 
AAaron123
Guest
Posts: n/a
 
      04-14-2009
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> On Apr 14, 8:43 am, "AAaron123" <(E-Mail Removed)> 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



 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      04-14-2009
On 14 Apr., 16:09, "Hillbilly" <(E-Mail Removed)> 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".
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
EJB entity with multiple parents (only one relationship persists?) ses Java 1 04-14-2011 01:00 AM
VOIP over VPN over TCP over WAP over 3G Theo Markettos UK VOIP 2 02-14-2008 03:27 PM
AJAX - Partial Postbacks are now Full Postbacks ?!! gregfocker@earthlink.net ASP .Net 0 01-25-2007 07:04 AM



Advertisments