views:

315

answers:

1

Let's say I have a custom template control, that can be used in pages like so:

<AR:CustomControl runat="server">
    <ViewTemplate>
        <span>stuff</span>
    </ViewTemplate>
</AR:ModalLink>

Since there is only one template field, the element isn't really necessary. Is there a way I can edit my control so it can be used like?

<AR:CustomControl runat="server">
    <span>stuff</span>
</AR:ModalLink>

Note that this is a UserControl with an ASCX file. So I don't think I can simple inherit from an existing control like Label.

A: 

Found the solution here: "http://alvinzc.blogspot.com/2006/10/aspnet-basic-of-custom-server-control_25.html"

In a nutshell:

[ParseChildren(true, "Content")]
[PersistChildren(false)]
public partial class CustomControl : System.Web.UI.UserControl
{
    ...

    [Browsable(false),
    PersistenceMode(PersistenceMode.InnerDefaultProperty),
    TemplateContainer(typeof(Contents)),
    TemplateInstance(TemplateInstance.Single)]
    public ITemplate Content { ... }
}
Frank Schwieterman
Link should be http://alvinzc.blogspot.com/2006/10/aspnet-basic-of-custom-server-control_25.html
Sean McMillan