Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Viewstate can contain only serializable object?

Tags:

c#

asp.net

I have a simple class with some properties and other data. Untill i stick serializable attribute to the class, i cannot save the object of the class into the viewstate.

Why Viewstate can contain only serializable objects?

like image 948
Karan Avatar asked Apr 30 '11 10:04

Karan


1 Answers

As the viewstate of a request is passed back to the browser as a serialised representation embedded within the generated page's HTML it makes sense that only serialisable objects can be placed within it (otherwise it may fail to represent that which it contains.) That viewstate is then de-serialised during the next request.

http://i.msdn.microsoft.com/dynimg/IC152667.gif gives an example of the typical

If you are using POCO's marking them as serialisable should be trivial enough. There is an excellent resource on understanding how viewstate works, what it is etc. here:

http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx

It goes into the full lifecycle of the state and gives detail about much of it's implementation and use from the prospective of a developer.

like image 101
Roja Buck Avatar answered Oct 09 '22 11:10

Roja Buck