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, INamingCont开发者_如何学运维ainer
{
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. 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
Key method to implement here is InstantiateIn()...
精彩评论