3

Currently I am using this line of code in my JavaScript

var tabIndex = $(':focus').attr('tabIndex'); 

However this constantly fails to get the active index.

Here is asp:TabContainer header in case this helps. I have also tried document.GetElementById, however to no avail as well.

    <asp:TabContainer ID="AdvOrBasicSearch" runat="server" ActiveTabIndex="0">
NealR
  • 10,189
  • 61
  • 159
  • 299
  • `:focus` selects the currently focused element in the page. If you want to select the current selected tab in a tab group, there is surely a better way around. – Fabrício Matté Sep 09 '12 at 03:06

3 Answers3

2

They say a picture is worth a thousand words...

I have used jQuery here. With it it is simple to find what you want. Pay attention to the rectangled text in the pic.

Happy coding.

enter image description here

deostroll
  • 11,661
  • 21
  • 90
  • 161
0

I found this method works much better. I created a variable with the tabContainer itself. Then, I just needed to go inside the variable and pull the value from the _activeTabIndex property.

var tabIndex = $find("AdvOrBasicSearch"); //AdvOrBasicSearch is name of tabContainer
var i = tabIndex._activeTabIndex; 
NealR
  • 10,189
  • 61
  • 159
  • 299
0

Get tab index and tab name using javascript

< script type="text/javascript">
        function onTabChanged(sender, e) <br> { <br>
            var curIndex = document.getElementById('lblCurTabNo');<br>
            var curName = document.getElementById('lblCurTabName');<br>
            curIndex.innerHTML = sender.get_activeTabIndex();<br>
            curName.innerHTML = sender.get_activeTab().get_headerText();<br>
        }<br>
    < /script><br><br>

< asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" UseVerticalStripPlacement="false"
            Width="400px" BackColor="ActiveBorder" ForeColor="Green" OnClientActiveTabChanged="onTabChanged"><br>
    ----asp tab control-----------

< /asp:TabContainer>

Tab Index : < asp:Label ID="lblCurTabNo" runat="server" Text="0"></asp:Label><br />

Tab Name :< asp:Label ID="lblCurTabName" runat="server" Text="Personal Info"></asp:Label>

Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
Jitendra G2
  • 1,196
  • 7
  • 14