must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in vi

  • Thread starter Harshdeep Mehta
  • Start date
H

Harshdeep Mehta

Hi all,

I have written a page in which I want to preserve value of object - suppose
A - value, so I used viewstate. but that give me error.

Code :
ViewState["ObjValue"] = objClassA; // Before PostBack
objClassA = (ClassA) ViewState["ObjValue"] // After PostBack

Any Body can help me out?

Thanks in advance.
 
T

Teemu Keiski

Hi,

as the error tells you, to put a class to ViewState it needs to be
serializable.

It means the object needs to have Serializable attribute so that Framework
serializes it automatically. If you want to customize this serialization
process to ease the task and make it explicit), you can additionally
implement ISerializable interface (means Serializable attribute must still
exist).

But with objects added to ViewState, it is recommended to implement a type
converter. If object has a type converter, it will be used to convert the
object to its string representation. Type converters are helper objects
which are used to object-to-string and string-to-object conversions. Using a
type converter gives the best possible performance (or in simple scenario
just convert the object to and from string manually).

here is how to develop a type converter:
http://msdn.microsoft.com/library/d...guide/html/cpconImplementingTypeConverter.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top