The TabTemplate property of the RadTab doesn't work

3 posts, 1 answers
  1. Foenix
    Foenix avatar
    20 posts
    Member since:
    Jul 2008

    Posted 14 Mar 2011 Link to this post

    Hello!
    I'm trying to customize RadTabStrip tab's appearance using the TabTemplate property. But it looks like this property doesn't work at all. I implemented a class to be used as a template:
    public class TestTabTpl : ITemplate
    {
        public void InstantiateIn(Control container)
        {
            // TODO: Implement this method
            Label lblCtrl = new Label();
      
            lblCtrl.Text = "Text message";
      
            container.Controls.Add(lblCtrl);
        }
    }

    Then when I'm trying to use it as a TabTemplate
    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (RadTab tab in RadTabStrip1.Tabs)
        {
            tab.TabTemplate = new TestTabTpl();
        }
    }
    it doesn't work.

    I've tried to test if the TestTabTpl class works using RadGrid:
    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (GridBoundColumn col in RadGrid1.Columns)
        {
            col.FilterTemplate = new TestTabTpl();
        }
    }

    And it works like a charm!

    Could you please verify if I'm using this property correctly or confirm that it can not be used from code?
    Thank you!
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Mar 2011 Link to this post

    Hello Foenix,

    Take a look at the following help article.
    Adding and Editing Templates at Runtime

    Thanks,
    Shinu.
  3. Foenix
    Foenix avatar
    20 posts
    Member since:
    Jul 2008

    Posted 16 Mar 2011 Link to this post

    Thank you very much, Shinu!

    This article was very helpful.

    To all:
    If you want to customize your tabs appearance without creating all tabs on the fly you can use following approach:
    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (RadTab tab in RadTabStrip1.Tabs)
        {
            switch (tab.Value)
            {
                case "Value1":
                    CustomTab1 tabTpl1 = new CustomTab1();
                    tabTpl1.InstantiateIn(tab);
                    break;
                case "Value2":
                    CustomTab2 tabTpl2 = new CustomTab2();
                    tabTpl2.InstantiateIn(tab);
                    break;
                default:
                    CustomTabDef tabTplDef = new CustomTabDef();
                    tabTplDef.InstantiateIn(tab);
                    break;
            }
        }
    }
Back to Top