[英]Custom WebControl with templates
I got this code which I wish to incorporate templates into. 我得到了此代码,希望将模板合并到其中。 Nothing fancy, just adding some content to a specific place in the control
没什么,只是将一些内容添加到控件中的特定位置
public class SiteTitle : WebControl, INamingContainer
{
public string Title { get; set; }
protected override void Render(HtmlTextWriter writer)
{
CreateSiteTitle(writer);
}
private void CreateSiteTitle(HtmlTextWriter writer)
{
writer.RenderBeginTag(HtmlTextWriterTag.H3);
writer.Write(this.Title);
// RENDER THE HTML FROM THE TEMPLATE
writer.RenderEndTag();
}
}
I wish to use it like so: 我希望这样使用它:
<my:SiteTitle ID="SiteTitle1" runat="server" Title="Test Control">
<RightContainer>
<p>HTML</p>
</RightContainer>
</my:SiteTitle>
I have tried messing with ITemplate and so, but I fail to do it. 我曾尝试将ITemplate弄乱,但我做不到。 Can someone provide an example on which I can work on?
有人可以提供我可以处理的示例吗?
Thanks! 谢谢!
Take a look at this: 看看这个:
http://msdn.microsoft.com/en-us/library/aa719862%28v=vs.71%29.aspx http://msdn.microsoft.com/zh-cn/library/aa719862%28v=vs.71%29.aspx
Key method to implement here is InstantiateIn()... 此处实现的关键方法是InstantiateIn()...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.