Storing custom objects in view state

Custom objects, i.e. your own objects can also be stored in view state. The only condition is that ASP.NET should be able to convert them into a stream of bytes so that it can be added to the hidden input field in the page. This process is called Serialization. If the objects aren’t serializable (which by default they aren’t), an error message would show while attempting to place them in view state.
To make the objects serializable, the [Serializable] attribute should be preceding the class declaration.

Hence, to check if the inbuilt class object can be stored in view state, go to class information in Visual Studio Help and find the Serializable attribute. If it exists it goes in the view state field, if it doesn’t, it doesn’t. :)

Follow

Get every new post delivered to your Inbox.