I’m trying to figure out if I can use the ITemplate interface in a custom control. Here is what I’ve done so far.
public class Tooltip : Control
{
public ITemplate ContentTemplate { get; set; }
protected override void CreateChildControls()
{
base.CreateChildControls();
var ctrl = new HtmlGenericControl("a");
if (ContentTemplate != null)
{
ContentTemplate.InstantiateIn(ctrl);
}
this.Controls.Add(ctrl);
}
}
The asp.net control usage
<gc:Tooltip runat="server">
<ContentTemplate>
hello
</ContentTemplate>
</gc:Tooltip>
The idea is that it should return something like this
<a>hello</a>
But the result looks like this
<ContentTemplate>
hello
</ContentTemplate>
<a></a>
It does include the template tags and seem to ignore whatever I do.
Any advice is appreciated
I was inheriting from the wrong class, when switching to WebControl it started working