I want to create a control just like Panel .
I want my control to accept some controls as children without entering a template name, like Panel , as shown below:
<asp:Panel runat="server"> My content <div>Content</div> </asp:Panel>
I have controls with content inside without telling what ITemplate .
I basically want to convert this
<my:MyControl runat="server"> <ContentTemplate> My content <div>Content</div> </ContentTemplate> </my:MyControl>
In that
<my:MyControl runat="server"> My content <div>Content</div> </my:MyControl>
Here is what I have:
public class MyControl : CompositeControl { [TemplateInstance(TemplateInstance.Single)] public ITemplate Content { get; set; } protected override void CreateChildControls() { base.CreateChildControls(); Content.InstantiateIn(this); } }
Above works with <Content></Content> tags inside the control, but does not work without it. And the attribute does nothing (I think). What is missing?
How can i achieve this? Any hints? Why does Panel support this?
Brunolm
source share