Adding tabs to a tabcontainer from code behind

Last post 11-09-2009 2:26 AM by MinaSamy. 1 replies.

Sort Posts:

  • Adding tabs to a tabcontainer from code behind

    11-08-2009, 6:45 AM
    • Member
      207 point Member
    • MinaSamy
    • Member since 12-17-2008, 8:04 AM
    • Posts 155

    Hi all I have a tab container declared as the following

    <

    cc1:TabContainer ID="TabContainer1" runat="server"> </cc1:TabContainer>

    When I try to add tanbs to this container from the code behind in the page load I use the following code

    protected void Page_Load(object sender, EventArgs e)
            {
                TabContainer1.Tabs.RemoveAt(0);
                AjaxControlToolkit.TabPanel panel1 = new AjaxControlToolkit.TabPanel();
                panel1.HeaderText = "panel1";
                panel1.Visible = true;
                panel1.ID = "panel1";
    
    
                AjaxControlToolkit.TabPanel panel2 = new AjaxControlToolkit.TabPanel();
                panel2.HeaderText = "panel2";
                panel2.Visible = true;
                panel2.ID = "panel2";
    
                TabContainer1.Controls.Add(panel1);
                TabContainer1.Controls.Add(panel2);
                
            }
    


     

    when I run the page nothing appears

    but if I declared a tabpanel as this

    <cc1:TabContainer ID="TabContainer1" runat="server">
         <cc1:TabPanel ID="ss" runat="server">
         <ContentTemplate>
         123
         </ContentTemplate>
         </cc1:TabPanel>
            </cc1:TabContainer>


     

    The same code works fine

    so I guess in order to add tabs programmatically you should have at least one tab declared

    is this assumption right ?

    thanks

    Mina Samy
    --------------------------------------------------
    http://www.learn-mvc.blogspot.com
  • Re: Adding tabs to a tabcontainer from code behind

    11-09-2009, 2:26 AM
    • Member
      207 point Member
    • MinaSamy
    • Member since 12-17-2008, 8:04 AM
    • Posts 155

    Ok I found it

    In order to make the tabs appear you should write

    TabContainer1.ActiveTabIndex = 0;

     

    and there is no need to declare a panel at the begining

    thanks

    Mina Samy
    --------------------------------------------------
    http://www.learn-mvc.blogspot.com
Page 1 of 1 (2 items)