Serialize Style to save ViewState

Discussion in 'ASP .Net Web Controls' started by Alex, Mar 16, 2005.

  1. Alex

    Alex Guest

    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
     
    Alex, Mar 16, 2005
    #1
    1. Advertising

  2. Alex

    Brock Allen Guest

    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.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > 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
    >
     
    Brock Allen, Mar 16, 2005
    #2
    1. Advertising

  3. Alex

    Alex Guest

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



    "Brock Allen" <_hate_spam_too> escribió en el mensaje
    news:...
    > 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.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    >> 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
    >>

    >
    >
    >
     
    Alex, Mar 16, 2005
    #3
  4. Alex

    Teemu Keiski Guest

    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" <> wrote in message
    news:%...
    >I must create my own Style inherited from Style with Attribute
    >Serializable() ?
    >
    >
    >
    > "Brock Allen" <_hate_spam_too> escribió en el mensaje
    > news:...
    >> 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.
    >>
    >> -Brock
    >> DevelopMentor
    >> http://staff.develop.com/ballen
    >>
    >>
    >>
    >>> 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
    >>>

    >>
    >>
    >>

    >
    >
     
    Teemu Keiski, Mar 25, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig Buchanan

    serialize class to the viewstate

    Craig Buchanan, Jan 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,189
  2. Gordz
    Replies:
    0
    Views:
    335
    Gordz
    Jun 2, 2004
  3. Gordz
    Replies:
    3
    Views:
    3,956
    John Oakes
    Jun 7, 2004
  4. Ben Amada

    Can viewstate serialize this class?

    Ben Amada, Oct 16, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    13,248
    john_teague
    Oct 30, 2005
  5. DC
    Replies:
    2
    Views:
    397
Loading...

Share This Page