Serialization problem with Web custom control

M

Michael Groeger

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?
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top