在Code Behind中创建ajaxToolkit TabPanel

时间:2012-01-25 15:35:13

标签: c# asp.net ajax ajaxcontroltoolkit

我有以下前端代码:

<ajaxToolkit:TabContainer runat="server" 
    Height="150px"
    Width="70%"
    ActiveTabIndex="1"        
    OnDemand="true"        
    AutoPostBack="false"
    TabStripPlacement="Top"
    CssClass="myTabs"
    ScrollBars="None"
    UseVerticalStripPlacement="false"
    ID="MyTabs"
    >

    <ajaxToolkit:TabPanel runat="server" HeaderText="Dummy" Enabled="false" Visible="false">
        <ContentTemplate>
            ...
        </ContentTemplate>
    </ajaxToolkit:TabPanel>

    <ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="Features & Benefits">
        <ContentTemplate>
            hey guys this is to hoping it works
        </ContentTemplate>
    </ajaxToolkit:TabPanel>


</ajaxToolkit:TabContainer>

有没有办法从代码后面创建tabpanel?

更新

发现这个:

protected override void OnInit(EventArgs e) 
{ 
    base.OnInit(e); 

    // Create the tab panel's content container 
    Control tabContent = new Control(); 

    TabPanel tab = new TabPanel(); 
    tab.ID = "tabPanel1"; 
    tab.HeaderText = "Dynamic Panel"; 

    Label label = new Label(); 
    label.Text = "This is a dynamic tab panel"; 
    tabContent.Controls.Add(label); 
    tab.Controls.Add(tabContent); 
    this.tabContainer1.Tabs.Add(tab); 
}

开:http://forums.asp.net/t/1137736.aspx/1

1 个答案:

答案 0 :(得分:2)

这样的事情?

TabPanel FirstTab= new TabPanel();  
FirstTab.ID = "Tab1";  
FirstTab.HeaderText = "First Tab";  

TabPanel SecondTab = new TabPanel();  
SecondTab.ID = "Tab2";  
SecondTab.HeaderText = "Second Tab";  

TabContainer1.Tabs.Add(FirstTab);  //add it to the Tab Container control 
TabContainer1.Tabs.Add(SecondTab);  

//to added content on it you can do like this 
Image _image = new Image();
_image.ID = "image";
_image.ImageUrl = "~/images/test.gif";
FirstTab.Controls.Add(image);

TabContainer1.ActiveTabIndex = 0;  // set your active tab index to display.