Lightbulb: How to add a Custom Class to ViewState

I was building a page today that allows an admin to do some configuration and doesn't save anything back to the server until the admin chooses. I could have used XML or a temporary SQL table, but I choose ViewState for now. I continually received the error: Type 'MyNamespace.MyClass' in Assembly 'App_Code.gvg30s8w, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable. Of course the error spells out what's wrong. But, because I was still flustered with my earlier issue, I didn't read into it far enough. Again, a search online turns up almost nothing. Finally, the light came on. To get it to work you will need to add the <Serializable> (in VB) or [serializable] (in C# to the beginning of your class. Well, back to the grind.

Published Thursday, January 03, 2008 8:45 PM by Jason N. Gaylord

Comments

# net how to add team explorer

Monday, April 07, 2008 4:54 PM by net how to add team explorer

Pingback from  net how to add team explorer

# net 2008 how to add team explorer

Monday, April 07, 2008 5:13 PM by net 2008 how to add team explorer

Pingback from  net 2008 how to add team explorer

# re: Lightbulb: How to add a Custom Class to ViewState

Tuesday, April 15, 2008 10:13 AM by omer katz

it's not [serializable] in C#

it's [Serializable]

Leave a Comment

(required) 
(required) 
(optional)
(required)