【发布时间】:2015-10-28 21:05:57
【问题描述】:
在所有的examples of Templated server controls中,包含模板的类继承自CompositeControl类,而CompositeControl类本身继承自WebControl类。
在我的应用程序中,我想要use Templates in my Control,但也继承自不同的类,该类既不继承自CompositeControl 也不继承自WebControl。
“模板”可能意味着很多东西,但我问的是这样的代码:
[
Browsable(false),
DefaultValue(null),
Description("The Template for the content of the Control"),
PersistenceMode(PersistenceMode.InnerProperty),
TemplateInstance(TemplateInstance.Single),
]
public ITemplate Content { get; set; }
和这样的 ASP.NET 代码:
<prefix:CustomControl ID="Control1" runat="server">
<Content>
<asp:Literal ID="ExampleContent" runat="server" Text="Look at me" />
</Content>
</prefix:CustomControl>
但是,我注意到,当我从 WebControl 类继承时,我的对象中的 ITemplate 变量具有我期望的数据,而如果我不从 WebControl 继承,这些变量具有 @ 987654332@数据。
如何使用模板变量,同时也继承自我选择的任何类?
【问题讨论】:
标签: c# asp.net custom-controls