943,576 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 4818
  • ASP.NET RSS
Dec 29th, 2005
0

lifetime of viewstate

Expand Post »
What is the lifetime of values within the viewstate.

for how much time are they going to store the values of our controls
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ramareddy_dotne is offline Offline
15 posts
since May 2005
Dec 29th, 2005
0

Re: lifetime of viewstate

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.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Dec 30th, 2005
0

Re: lifetime of viewstate

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.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Dec 31st, 2005
0

Re: lifetime of viewstate

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Reham Ejaz is offline Offline
23 posts
since Nov 2005
Dec 31st, 2005
0

Re: lifetime of viewstate

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
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Jan 2nd, 2006
0

Re: lifetime of viewstate

Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Reham Ejaz is offline Offline
23 posts
since Nov 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Problem With database Connectivity
Next Thread in ASP.NET Forum Timeline: what is tab in asp.net?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC