Saving a Collection to ViewState

A

Angel

I built a webcontrol and within the control I build a collection of properties I would Like to store so I do not have to rebuild it everytime there is a postback. I store the collection in viewstate and get the following error when I run a page with my control on it:

The Type 'myCollection' must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in viewstate.

I store all my other custom properties in viewstate, but accessing myCollection from the viewstate becomes an error. I know that myCollection is not a basic type, while the other properties are, but is there a way to save the collection without having to rebuild it everytime there is a postback?

Thanks...
 
A

Angel

Before the Class that I use into a collection I marked it with <Serializable()> and it still does not work...

Any ideas why not?

Thanks
 
A

Andy Z Smith

I think you will need to implement some custom serializers. The framework does not know to to serialize every possible class type that you can create. I've not done this but I think that's what it is.

My suggestion is to throw the stuff into something that is natively serializable. Add the salient parts of the collection to an ArrayList or a DataTable or something and shove it ViewState or Session.

Andrew
 
V

Victor Garcia Aprea [MVP]

Take a look at this[1] post to learn how the viewstate serializer works and
what you can do in order to get your data serialized fast and with the
smallest possible footprint.

[1]
http://weblogs.asp.net/vga/archive/2004/05/11/DontLetTheBinaryFormatterGetAtIt.aspx

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx

Andy Z Smith said:
I think you will need to implement some custom serializers. The framework
does not know to to serialize every possible class type that you can create.
I've not done this but I think that's what it is.
My suggestion is to throw the stuff into something that is natively
serializable. Add the salient parts of the collection to an ArrayList or a
DataTable or something and shove it ViewState or Session.
 

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