用户选择标签时,如何从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>
最佳答案
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());
}