Reputation: 1663
OK, let me be more specific. I know how to create a control with a collection property, but what I've never done is written one that has markup associated with it.
What I want to know is, given an control defined like this ...
public class MyControl
{
public List<MySubItems> Items {get; set;}
}
What do I have to do to be able to create markup, like this...
<MyStuff:MyControl runat="server" ID="MyControl1">
<Items>
<MySubItem ... />
<MySubItem ... />
</Items>
</MyStuff:MyControl>
Apologies if this seems a bit of a noddy question, but I've never done this before.
-- Stuart
Upvotes: 1
Views: 68
Reputation: 9356
You'll need to apply the DesignerSerializationVisibilityAttribute along with PersistenceModeAttribute on your property. Assuming it's a ASP.NET control.
This is what it would look like -
public class MyControl:WebControl
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public List<MySubItems> Items {get; set;}
}
See MSDN: Web Control Collection Property Example for a detailed example.
Upvotes: 3
Reputation: 5914
You are probably looking for Templated controls http://msdn.microsoft.com/en-us/library/aa478964.aspx
Upvotes: 1