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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.
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.