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.
Like every other day, I’m blowing through some really complex code trying to create hacks to get around difficult issues. Then, a road block. I have a mind freeze and oops, I forgot what the issue is. I had that earlier today when I forgot how to access the item index number in an ItemTemplate of a DataList or Repeater. I pinged the aspadvice.com lists and Ryan Trudelle-Schwarz responded (although he forgot the big Duh! on the top) to use the Container.ItemIndex. Low and behold, adding this: <%# Container.ItemIndex %> to your code does spit out the Item Index number. After a good hour or so of searching MSDN trying to find it, Ryan came to the rescue. Thanks again Ryan for kick starting my brain.