Viewsatate

  • Thread starter Thread starter Brian Shannon
  • Start date Start date
B

Brian Shannon

I am curious about viewstate. I thought viewstate is pretty much handled by
ASP.NET but I have read a lot about uses of calling/retrieving values from
viewstate or saving a value to viewstate. If viewstate is managed by
ASP.NET in what cases does it need to be managed by the developer?

Does anyone have some good articles on viewstate that could better help me?

Thanks
 
ViewState is pretty much handled by ASP.NET but is exposed so that a
developer can use it to persist data across postbacks. It becomes yet
another option for retaining state. One example of when you would tap into
this is User Controls. Let's say you create an Order User Control that has
an OrderID property. You could persist that property to viewstate and then
the caller could set the property just once not after every postback.

This article tells everything you'd ever want to know about viewstate:
http://msdn.microsoft.com/msdnmag/issues/03/02/CuttingEdge/
 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspnet/html/asp11222001.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/viewstate.asp

Hope this helps.

I am curious about viewstate. I thought viewstate is pretty much handled by
ASP.NET but I have read a lot about uses of calling/retrieving values from
viewstate or saving a value to viewstate. If viewstate is managed by
ASP.NET in what cases does it need to be managed by the developer?

Does anyone have some good articles on viewstate that could better help me?

Thanks
 
ViewState is similar to many ASP.Net entities in that it has a server-side
component and a client-side component. The client-side component is a hidden
form field containing the compressed values of all ViewState objects in the
Page. On the server-side, ViewState is a serializable Name-Value Collection
that is a property of each Control (each Control has and manages its own
ViewState). Because it is a public Collection, it is accessible on the
server programmatically, and you can read, add, modify, and remove elements
from the Collection.

To say that ViewState is "handled by ASP.Net" is only partially correct.
Every Control that uses ViewState manages its' own ViewState (not ASP.Net er
se). However, there are times when you may want to persist some serialzable
data across PostBacks without using Session or some other server-side
caching mechanism. By adding that data to the Page's ViewState, or any of
its Controls ViewState, you can do this. Also, you may develop your own
Server Controls, in which case you will have to write the code that manages
its ViewState.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top