开发者

Custom WebControl with templates

开发者 https://www.devze.com 2023-04-06 11:04 出处:网络
I got this code which I wish to incorporate templates into. Nothing fancy, just adding some content to a specific place in the control

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()...

0

精彩评论

暂无评论...
验证码 换一张
取 消