按Tab键在TabContainer中切换Ajax选项卡

时间:2012-10-14 21:00:27

标签: c# asp.net html ajax ajaxcontroltoolkit

我有一个ajax控件工具包TabContainer。使用c#以下面的方式控制活动选项卡。我的tabcontainer上有很多标签。

是否可以通过引用C#中的选项卡ID而不是选项卡的编号来切换选项卡?

c#中

TabContainerMain.ActiveTabIndex = 5;

HTML

<asp:TabContainer ID="TabContainerMain" runat="server" ActiveTabIndex="4" Width="100%"
    Height="100%" CssClass="" ViewStateMode="Enabled">
    <asp:TabPanel runat="server" HeaderText="Tab_Monitor" ID="Tab_Monitor">
    </asp:TabPanel>
    <asp:TabPanel ID="Tab_Remove_Item" runat="server" HeaderText="Tab_Remove_Item">
        <ContentTemplate>
            <div class="TabControls">
                <p>
                    Howdy, I'm in Section Tab_Remove_Item .</p>
            </div>
            <div class="TabsAction">
            </div>
        </ContentTemplate>
    </asp:TabPanel>
    <asp:TabPanel ID="Tab_2nd_Sign_System" runat="server" HeaderText="Tab_2nd_Sign_System">
        <ContentTemplate>
            <div class="TabControls">
                <p>
                    Howdy, I'm in Section Tab_2nd_Sign_System .</p>
            </div>
            <div class="TabsAction">
            </div>
        </ContentTemplate>
    </asp:TabPanel>
    <asp:TabPanel ID="Tab_Configure_Device" runat="server" HeaderText="Tab_Configure_Device">
        <ContentTemplate>
            <div class="TabControls">
                <p>
                    Howdy, I'm in Section Tab_Configure_Device .</p>
            </div>
            <div class="TabsAction">
            </div>
        </ContentTemplate>
    </asp:TabPanel>
</asp:TabContainer>

1 个答案:

答案 0 :(得分:2)

是的,您可以使用ActiveTab属性。例如:

获取

if(TabContainerMain.ActiveTab == this.Tab_Remove_Item)
{
    // ...
}

TabContainerMain.ActiveTab = this.Tab_2nd_Sign_System;

如果您只将ID作为字符串,则可以使用LINQ(或循环)来获取引用:

String tabPanelID = "Tab_Remove_Item";
TabContainerMain.ActiveTab = TabContainerMain.Tabs
    .Cast<AjaxControlToolkit.TabPanel>()
    .First(t => t.ID == tabPanelID);