Serialization problem with Web custom control

Discussion in 'ASP .Net Web Controls' started by Michael Groeger, Nov 16, 2004.

  1. Hi everybody,

    I am fairly new to asp.net and creating web custom controls. I am
    trying to implement a control, which has a collection of items and
    where new items can be added at runtime.
    It's implemented somehow like this:

    public class MyControl : System.Web.UI.WebControl
    {
    private ItemCollection _Items;

    public ItemCollection Items
    {
    if (ViewState["MyControlItems"] != null)
    _Items = (ItemCollection) ViewState["MyControlItems"]
    else
    _Items = new ItemCollection();
    return _Items;
    }

    private void Items_CollectionChanged(object sender, EventArgs e)
    {
    ViewState["MyControlItems"] = _Items;
    }

    // [...]
    }

    [Serializable()]
    public class ItemCollection : CollectionBase
    {
    // implements this[], Add, Remove and IndexOf
    // Add/Remove raise the CollectionChanged event
    }

    [Serializable()]
    public class Item
    {
    private string _Upper;
    private string _Lower;
    private string _Cap;

    public string Upper
    {
    get { return _Upper; }
    set { _Upper = value; }
    }

    public string Lower
    {
    get { return _Lower; }
    set { _Lower = value; }
    }

    public string Cap
    {
    get { return _Cap; }
    set { _Cap = value; }
    }

    }

    Now, when I try to add a new Item at runtime, I get the following
    error:

    'StammdatenControls.ItemCollection' must be marked as Serializable or
    have a TypeConverter other than ReferenceConverter to be put in
    viewstate.]
    System.Web.UI.LosFormatter.SerializeValue(TextWriter output, Object
    value)
    System.Web.UI.LosFormatter.SerializeValue(TextWriter output, Object
    value)
    System.Web.UI.LosFormatter.SerializeValue(TextWriter output, Object
    value)
    System.Web.UI.LosFormatter.SerializeInternal(TextWriter output,
    Object value)
    System.Web.UI.LosFormatter.Serialize(TextWriter output, Object
    value)
    System.Web.UI.LosFormatter.EstimateSize(Object obj)
    System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
    calcViewState)
    System.Web.UI.Page.ProcessRequestMain()

    Can somebody help?
    Michael Groeger, Nov 16, 2004
    #1
    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. Replies:
    8
    Views:
    2,227
    deadsea
    Jan 2, 2005
  2. Replies:
    3
    Views:
    1,011
  3. Dimitri Ognibene
    Replies:
    4
    Views:
    767
    Dimitri Ognibene
    Sep 2, 2006
  4. Matt Sokol
    Replies:
    2
    Views:
    366
    Theo Tillotson
    Aug 7, 2003
  5. Ramunas Urbonas
    Replies:
    1
    Views:
    383
    Dino Chiesa [Microsoft]
    Jul 27, 2004
Loading...

Share This Page