Mohammad Dayyan
Mohammad Dayyan

Reputation: 22458

Rendering controls within a Template tag in a custom ServerControl?

I'm working on a custom navigation menu,
I've added the following property within my MenuItem class to allow users add them controls into it.

public class MenuItem : INamingContainer
{
.
.
.
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public ITemplate Template { get; set; }
}

I can add the tags in asp.net without any troubles but the controls within Template aren't render!!! and I'm not receive any Exceptions or Errors !

<MdsMenu:Menu ID="Menu1" runat="server">
    <MdsMenu:MenuItem Text="MenuItem 01" href="#" />
    <MdsMenu:MenuItem Text="MenuItem 02" href="#">
        <MdsMenu:MenuItem href="#" Text="Template">
            <Template>
                <asp:Button ID="Button1" runat="server" Text="Button" />
            </Template>
        </MdsMenu:MenuItem>
    </MdsMenu:MenuItem>
    <MdsMenu:MenuItem Text="MenuItem 03" href="#" />
    <MdsMenu:MenuItem Text="MenuItem 04" href="#" />
</MdsMenu:Menu>

How can I render them ?

Upvotes: 0

Views: 1114

Answers (1)

VinayC
VinayC

Reputation: 49245

You have to instantiate your template within some container. See below article for how to develop template based controls:

http://msdn.microsoft.com/en-us/library/36574bf6.aspx - see example for quick start http://msdn.microsoft.com/en-us/library/aa478964.aspx - this is more detailed article

Upvotes: 1

Related Questions