views:

421

answers:

2

I'm looking to do something akin to

<cstm:MyControl runat="server">
    <myItem attr="something" />
    <myItem attr="something" />
</cstm:MyControl>

What's the bare bones code needed to pull this off?

Rick's example shows something akin to

<cstm:MyControl runat="server">
    <myItems>
        <cstm:myItem attr="something" />
        <cstm:myItem attr="something" />
    </myItems>
</cstm:MyControl>

I'd prefer the more terse syntax if possible.

Note: Feel free to suggest a better title or description. Even if you don't have edit rights, I'm glad to edit the entry for the sake of the community.

+3  A: 

I was able to implement this after following Rick Strahl's examples:
http://www.west-wind.com/weblog/posts/200.aspx

AaronSieb
His example shows a nesting of webTabControl->tabpages->tabpage. If possible, I'd like to eliminate the "tabpages" part and just nest the tabpage within the webTabControl.
Larsenal
+5  A: 

Here's a really simple example control that does exactly what you are looking for:

namepsace TestControl
{
    [ParseChildren(true, DefaultProperty = "Names")]
    public class MyControl : Control
    {
        public MyControl()
        {
            this.Names = new List<PersonName>();
        }

        [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
        public List<PersonName> Names { get; set; }
    }

    public class PersonName
    {
        public string Name { get; set; }
    }
}

And, here's example usage:

<%@ Register Namespace="TestControl" TagPrefix="TestControl"  %>

<TestControl:MyControl runat="server" ID="MyControl1">
    <TestControl:PersonName Name="Chris"></TestControl:PersonName>
    <TestControl:PersonName Name="John"></TestControl:PersonName>
</TestControl:MyControl>
Chris Pietschmann