Serialize Style to save ViewState

A

Alex

Hi,
I've the follow error:
"The type 'ViewStateControl.MyCollection' must be marked as Serializable or
have a TypeConverter other than ReferenceConverter to be put in viewstate."
MyCollection has the attributte Serializable(). MyCollection is a collection
of MyItem (Serializable()). If i remove the Property Style (Type
System.Web.UI.WebControls.Style), the error don't happend.
Somebody can help me? :(

Thanks
 
B

Brock Allen

If you want to store your own types (classes) in ViewState you need to mark
them with the Serializable attribute, which grants permission to store them
in the ViewState persistence medium.

[Serializable]
class MyCollection : SomeBase
{
}

Also, any items that go into the collection also need to be marked with the
Serializable attribute. BTW, it's <Serializable> in VB.NET.
 
A

Alex

I must create my own Style inherited from Style with Attribute
Serializable() ?



Brock Allen said:
If you want to store your own types (classes) in ViewState you need to
mark them with the Serializable attribute, which grants permission to
store them in the ViewState persistence medium.

[Serializable]
class MyCollection : SomeBase
{
}

Also, any items that go into the collection also need to be marked with
the Serializable attribute. BTW, it's <Serializable> in VB.NET.




Hi,
I've the follow error:
"The type 'ViewStateControl.MyCollection' must be marked as
Serializable or
have a TypeConverter other than ReferenceConverter to be put in
viewstate."
MyCollection has the attributte Serializable(). MyCollection is a
collection
of MyItem (Serializable()). If i remove the Property Style (Type
System.Web.UI.WebControls.Style), the error don't happend.
Somebody can help me? :(
Thanks
 
T

Teemu Keiski

I dropped off the track how you have it currently, but here is a link to an
example howto save Style object to your control's Viewstate. Instead of
passing the style to ViewState straight, you use it's IStateManager
interface implementation to let the style itself save/load/track the state
and let the control put/take that state data to/from Viewstate and hand to
the style object.

Instead of passing the object to Viewstate, let it hand you the state, and
put only that state to Viewstate (saves CPU cycles as entire object doesn't
need to be serialized plus that Binary serialization is slow). Anyway here's
an example of a control I wrote which uses custom style and saves its data
to control's Viewstate

http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=842466

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU



Alex said:
I must create my own Style inherited from Style with Attribute
Serializable() ?



Brock Allen said:
If you want to store your own types (classes) in ViewState you need to
mark them with the Serializable attribute, which grants permission to
store them in the ViewState persistence medium.

[Serializable]
class MyCollection : SomeBase
{
}

Also, any items that go into the collection also need to be marked with
the Serializable attribute. BTW, it's <Serializable> in VB.NET.




Hi,
I've the follow error:
"The type 'ViewStateControl.MyCollection' must be marked as
Serializable or
have a TypeConverter other than ReferenceConverter to be put in
viewstate."
MyCollection has the attributte Serializable(). MyCollection is a
collection
of MyItem (Serializable()). If i remove the Property Style (Type
System.Web.UI.WebControls.Style), the error don't happend.
Somebody can help me? :(
Thanks
 

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,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top