4

How can I select a tab programmatically of a TabContainer? and also how can I get the selected Tab?

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
user710502
  • 11,181
  • 29
  • 106
  • 161
  • I haven't touched those in awhile, but off the top of my head, I beilive it has a SelectedIndex property you can set to change the index. – asawyer Jul 26 '11 at 15:29

3 Answers3

3

You can set the Tab Index like...

tbcName.ActiveTabIndex = 3;

and similarly

tbcName.ActiveTabIndex// Return active tab index

Please note, tab Index start from 0

Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
  • When I click on my Submit button and I am on tab 3, on Postback it is still bringing me to the first tab.. i want to come back on the tab index i had selected – user710502 Jul 26 '11 at 15:48
  • Tab control does not maintain tab index on postback, have a check these links http://www.codeproject.com/KB/ajax/maintaining-active-tab.aspx http://forums.asp.net/p/1300797/2548838.aspx – Muhammad Akhtar Jul 26 '11 at 15:53
1

Here is a complete list of TabContainer's properties taken from here:

TabContainer Properties

    ActiveTabChanged (Event) - Fired on the server side when a tab is changed after a
postback
    OnClientActiveTabChanged - The name of a javascript function to attach to the
client-side tabChanged event
    CssClass - A css class override used to define a custom look and feel for the tabs.
See the Tabs Theming section for more details.
    ActiveTabIndex - The first tab to show
    Height - sets the height of the body of the tabs (does not include the TabPanel
headers)
    Width - sets the width of the body of the tabs
    ScrollBars - Whether to display scrollbars (None, Horizontal, Vertical, Both, Auto)
in the body of the TabContainer
    TabStripPlacement - Whether to render the tabs on top of the container or below
(Top, Bottom)

Useful links with sample code:

http://sandblogaspnet.blogspot.com/2009/04/setting-focus-to-particular-tab-in.html

tabContainer = tabContainer.control;
//Retrieving the tab using the get_activeTab method/property
var tab = tabContainer.get_activeTab();
var headerText = tab.get_headerText();
alert(headerText);
//Another way of retrieving the tab using the get_previousTab method/property
tab = tabContainer.getPreviousTab();
alert(tab.get_tabIndex());

3 Tips for Working with the AjaxControlToolkit's TabContainer Control

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
1
yourTabContainer.ActiveTab = tabIndex;
Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
Itay
  • 45
  • 1
  • 6