lifetime of viewstate

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2005
Posts: 15
Reputation: ramareddy_dotne is an unknown quantity at this point 
Solved Threads: 0
ramareddy_dotne ramareddy_dotne is offline Offline
Newbie Poster

lifetime of viewstate

 
0
  #1
Dec 29th, 2005
What is the lifetime of values within the viewstate.

for how much time are they going to store the values of our controls
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: lifetime of viewstate

 
0
  #2
Dec 29th, 2005
Viewstate "lives" in a hidden variable embedded within the form. Thus, it is resident client-side. While the user is looking at the page, the ASP.NET application isn't "running". Thus, Viewstate doesn't exist at all.

When the users posts the form, IIS/ASP.NET go through a series of steps, one of them being the re-building of the state-bag (ViewState) from the HTTP Request object (remember, Viewstate is a hidden form variable, so is posted in the Request).

The Page Life-Cycle goes on, eventually calling any event handlers, and building the Response. This includes re-packaging the NEW Viewstate into the hidden variable. The Response is shipped back to the client, and your application goes back into non-existence until the user posts again.

Thus, ViewState only "lives" as long as it takes your application to generate a Response.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: lifetime of viewstate

 
0
  #3
Dec 30th, 2005
Also... Viewstate does not store the "vaules of... controls". The HTTP Request mechanism does that.

Well, that's almost right. Let's say that Viewstate does not store the value of Form Elements. What it does is store the "state" of any controls that have had their attributes altered server-side. For example say you use an ASP.NET Label control, with an initial setting. In response to some event, you change the value of that Label. The Viewstate mechanism would be used to transport that new value to the client.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 23
Reputation: Reham Ejaz is an unknown quantity at this point 
Solved Threads: 0
Reham Ejaz Reham Ejaz is offline Offline
Newbie Poster

Re: lifetime of viewstate

 
0
  #4
Dec 31st, 2005
Very Impressive. Then why do we use The ViewState object as it loses any information as soon as we move to any other page within the same site?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: lifetime of viewstate

 
0
  #5
Dec 31st, 2005
Because Viewstate is scoped to that particular "instance" of that particular page. It has no relevance whatsoever to another page within that application. If you need to maintain some value across the application, you'd use the Session object instead.

I explain ViewState here: http://www.tgreer.com/aspnet_html_02.html

I explore ViewState, Session, the ASP.NET Page Life Cycle, and conditional dynamic controls in this article: http://www.tgreer.com/aspnet_html_04.html
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 23
Reputation: Reham Ejaz is an unknown quantity at this point 
Solved Threads: 0
Reham Ejaz Reham Ejaz is offline Offline
Newbie Poster

Re: lifetime of viewstate

 
0
  #6
Jan 2nd, 2006
Thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC