0
我試圖弄清楚我是否可以在自定義控件中使用ITemplate
界面。這是我迄今爲止所做的。在自定義控件中使用ITemplate
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);
}
}
的asp.net控制使用
<gc:Tooltip runat="server">
<ContentTemplate>
hello
</ContentTemplate>
</gc:Tooltip>
的想法是,它應該返回像這樣
<a>hello</a>
但結果看起來像這樣
<ContentTemplate>
hello
</ContentTemplate>
<a></a>
它包含模板標籤似乎無視我所做的任何事情。
任何建議表示讚賞
謝謝,我確實看了看,但它建議我應該創建一個外部控制,我正在尋找解決方案,我可以直接實現模板。從WebControl繼承而不是Control解決了我的問題。 –
很高興聽到這一點。乾杯 – Rikki