How to get active tab index from TabContainer
-
01-07-2021 - |
Pergunta
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">
Solução 2
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;
Outras dicas
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.
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>