1

当用户选择选项卡时,如何从 TabContainer 获取 ActiveTabIndex?我尝试了以下但不起作用。

<script type="text/javascript">
    function TabChange() {
        var tc = document.getElementById("TabContainer1")
        alert(tc.ActiveTabIndex);
    }
</script>

 <asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" Height="300px"
        Width="300px" CssClass="MyTabStyle" OnClientActiveTabChanged="TabChange">
        <asp:TabPanel runat="server" HeaderText="First" ID="TabPanel1">
            <ContentTemplate>
                <h1>
                    Tab 1
                </h1>
            </ContentTemplate>
        </asp:TabPanel>
        <asp:TabPanel ID="TabPanel2" runat="server" HeaderText="Second">
            <ContentTemplate>
                <h1>
                    Tab 2
                </h1>
            </ContentTemplate>
        </asp:TabPanel>
 </asp:TabContainer>
4

1 回答 1

5

ASPX:

<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" OnClientActiveTabChanged="clientActiveTabChanged">
<ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="Test1">
    <ContentTemplate>Test1</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel2" runat="server" HeaderText="Test2">
    <ContentTemplate>Test2</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel3" runat="server" HeaderText="Test3">
    <ContentTemplate>Test3</ContentTemplate>
</ajaxToolkit:TabPanel>


JS:

<script type="text/javascript">

function clientActiveTabChanged(sender, args) {

    alert(sender.get_activeTabIndex());
}

于 2012-10-31T13:34:42.820 回答