Reputation: 2929
I'm trying to create a user control that allows users to make something like the following:
<uc1:MyControl id="controlThing" runat="server">
<uc1:BoundColumn id="column1" Column="Name" runat="server" />
<uc1:CheckBoxBoundColumn id="column2" Column="Selector" runat="server" />
<uc1:BoundColumn id="column3" Column="Description" runat="server" />
...etc
</uc1:MyControl>
There are only certain controls I would allow, in addition to the fact that you can have many of any type. I can picture this in XSD, but I'm not entirely sure for ASP.NET.
My ASP.NET voodoo is drawing a blank right now.. any thoughts?
Upvotes: 0
Views: 1194
Reputation: 12451
The PersistenceMode.InnerProperty is what you want.. Here are the MSDN docs. Doing something like this will get you what you want:
[PersistenceMode(PersistenceMode.InnerProperty)]
public ListItem Items {
get; set;
}
and then you'll be able to use it like this:
<cc1:MyControl runat="server">
<Items>
<asp:ListItem Text="foo" />
</Items>
</cc1:MyControl>
You can create your own custom classes to use in there as well.
Upvotes: 2
Reputation: 2929
I suppose the most difficult part I'm concerned with is being able to template any number of a given set of user controls inside my user control.
<mycontrol id="control1" runat="server">
<templateitem id="bleh1" runat="server" />
<templateitem id="bleh2" runat="server" />
<templateitem id="bleh3" runat="server" />
..etc
</mycontrol>
Upvotes: 0
Reputation: 25099
Is it possible for you to override an existing control such as a ListView or GridView? That's your simplest option.
But to create your own custom templated control you need to use ITemplate.
I haven't done one but a quick google returned this: http://www.developerfusion.com/article/4410/in-depth-aspnet-using-adonet/2/ it looked good.
I have a book "Developing Microsoft ASP.NET Server Controls and Components" which covers it but I haven't read through it indepth yet (http://www.amazon.com/exec/obidos/ASIN/0735615829/nikhilkothari-20)
Upvotes: 0