Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Custom WebControls with Collection property

Hi,

I've been working on a custom WebControl. I want it to have a property "Items" that contains a collection of custom objects and I want the control to behave within the VS IDE like a Listbox WebControl, generating the following "HTML" tags
<asp:ListBox id="ListBox1" runat="server">
    <asp:ListItem Value="1">First</asp:ListItem>
    <asp:ListItem Value="2">Second</asp:ListItem>
</asp:ListBox>

My code looks like this
<cc1:MyControl id="MyControl1" runat="server">
    <cc1:CustomItem prop1="1" prop2="aa"></cc1:CustomItem>
    <cc1:CustomItem prop1="2" prop2="bb"></cc1:CustomItem>
</cc1:MyControl>

I have everything working except for one little detail:
If I change the items in the collection using the property collection editor the updated items are not generated back into the aspx file. Instead I get this:

<cc1:MyControl id="MyControl1" runat="server" Items="(Collection)"></cc1:MyControl>

Can anyone tell me what attribute, property or override I should use to let the control generate the child tags instead of the Items="(Collection)" attribute?

Thanks

Gee
Monday, February 07, 2005

OK, I got it

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]    
public MyCollection Items
{
    get { return _items; }
}

Gee
Monday, February 07, 2005

*  Recent Topics

*  Fog Creek Home