Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / June 2004

Tip: Looking for answers? Try searching our database.

Saving a Collection to ViewState

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Angel - 10 Jun 2004 19:40 GMT
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...
Natty Gur - 11 Jun 2004 10:19 GMT
Hi,

you need to mark your collection or derived classes, if exist, with
Serialization attribute.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377
Angel - 11 Jun 2004 14:15 GMT
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

> Hi,
>
[quoted text clipped - 8 lines]
> *** Sent via Devdex http://www.devdex.com ***
> Don't just participate in USENET...get rewarded for it!
Andy Z Smith - 18 Jun 2004 01:23 GMT
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

> Before the Class that I use into a collection I marked it with <Serializable()> and it still does not work...
>
[quoted text clipped - 14 lines]
> > *** Sent via Devdex http://www.devdex.com ***
> > Don't just participate in USENET...get rewarded for it!
Victor Garcia Aprea [MVP] - 24 Jun 2004 00:15 GMT
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

Signature

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

> 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
>
[quoted text clipped - 16 lines]
> > > *** Sent via Devdex http://www.devdex.com ***
> > > Don't just participate in USENET...get rewarded for it!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.