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?
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?