M
mehdi.mousavi
Hi folks,
I'm developing a WebControl, that has got a property that's supposed to
return a collection of data. Whenever I try to populate the mentioned
collection under the visual designer, the items I add to the collection
are not displayed in the .aspx file.
Here's what I would like to have, when an item named "txt1" with value
"val1" is added in the collection editor:
<wcl:MyList ID="MyList1" runat="server" Items-Capacity="4">
<wcl:MyItem Text="txt1" Value="val1" />
</wcl:MyList>
However, the
<wcl:MyItem Text="txt1" Value="val1" />
line is not added to the file, after closing the collection editor.
Another amazing aspect of this control is the "Items-Capacity" property
that's being concatenated to the above-declaration. I've got no idea
what it is, too! Here's some code-snippet that may help to pinpoint the
problem.
[ToolboxData("<{0}:MyList runat=server></{0}:MyList>")]
[ToolboxBitmap(typeof(MyList), "WebCtrlLib.MyList.ico")]
[AspNetHostingPermission(SecurityAction.Demand, Level =
AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level =
AspNetHostingPermissionLevel.Minimal)]
[DefaultProperty("Items")]
[ParseChildren(true, "Items")]
[Designer(typeof(MyListContainerControlDesigner))]
public class MyList: WebControl, INamingContainer
{
//removed for brevity
[Category("Misc")]
[Description("The collection of items in the list.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(MyItemCollectionEditor), typeof(UITypeEditor))]
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public MyItemCollection Items
{
get
{
if(m_coll == null)
{
m_coll = new MyItemCollection();
if(IsTrackingViewState)
((IStateManager)m_coll).TrackViewState();
}
return m_coll;
}
}
}
public abstract class StateManagedCollectionBase<T>: CollectionBase,
IViewState, IStateManager where T: class
{
/*
public void Add(T item)
public void Remove(int nIndex)
public void Remove(T item)
public T this[int index]*/
}
public class MyItemCollection: StateManagedCollectionBase<MyItem>
{
}
class MyItemCollectionEditor: CollectionEditor
{
public MyItemCollectionEditor(Type type): base(type)
{
}
protected override bool CanSelectMultipleInstances()
{
return false;
}
protected override Type CreateCollectionItemType()
{
return typeof(MyItem);
}
}
public class MyListContainerControlDesigner: ContainerControlDesigner
{
public override DesignerAutoFormatCollection AutoFormats
{
//removed for brevity
}
}
Any help would be highly appreciated.
Cheers,
M.Mousavi
I'm developing a WebControl, that has got a property that's supposed to
return a collection of data. Whenever I try to populate the mentioned
collection under the visual designer, the items I add to the collection
are not displayed in the .aspx file.
Here's what I would like to have, when an item named "txt1" with value
"val1" is added in the collection editor:
<wcl:MyList ID="MyList1" runat="server" Items-Capacity="4">
<wcl:MyItem Text="txt1" Value="val1" />
</wcl:MyList>
However, the
<wcl:MyItem Text="txt1" Value="val1" />
line is not added to the file, after closing the collection editor.
Another amazing aspect of this control is the "Items-Capacity" property
that's being concatenated to the above-declaration. I've got no idea
what it is, too! Here's some code-snippet that may help to pinpoint the
problem.
[ToolboxData("<{0}:MyList runat=server></{0}:MyList>")]
[ToolboxBitmap(typeof(MyList), "WebCtrlLib.MyList.ico")]
[AspNetHostingPermission(SecurityAction.Demand, Level =
AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level =
AspNetHostingPermissionLevel.Minimal)]
[DefaultProperty("Items")]
[ParseChildren(true, "Items")]
[Designer(typeof(MyListContainerControlDesigner))]
public class MyList: WebControl, INamingContainer
{
//removed for brevity
[Category("Misc")]
[Description("The collection of items in the list.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(MyItemCollectionEditor), typeof(UITypeEditor))]
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public MyItemCollection Items
{
get
{
if(m_coll == null)
{
m_coll = new MyItemCollection();
if(IsTrackingViewState)
((IStateManager)m_coll).TrackViewState();
}
return m_coll;
}
}
}
public abstract class StateManagedCollectionBase<T>: CollectionBase,
IViewState, IStateManager where T: class
{
/*
public void Add(T item)
public void Remove(int nIndex)
public void Remove(T item)
public T this[int index]*/
}
public class MyItemCollection: StateManagedCollectionBase<MyItem>
{
}
class MyItemCollectionEditor: CollectionEditor
{
public MyItemCollectionEditor(Type type): base(type)
{
}
protected override bool CanSelectMultipleInstances()
{
return false;
}
protected override Type CreateCollectionItemType()
{
return typeof(MyItem);
}
}
public class MyListContainerControlDesigner: ContainerControlDesigner
{
public override DesignerAutoFormatCollection AutoFormats
{
//removed for brevity
}
}
Any help would be highly appreciated.
Cheers,
M.Mousavi