views:

944

answers:

4

How can I tell my TabControl to set the focus to its first TabItem, something like this:

PSEUDO-CODE:

((TabItem)(MainTabControl.Children[0])).SetFocus();
+3  A: 

How about this?

MainTabControl.SelectedIndex = 0;
Martin Liversage
A: 
tabControl1.SelectedTab = item;
item.Focus();
Chernikov
A: 

tabControl.SelectedItem = tabControl.Items[0];

Ray
A: 

If you have a Tabcontroller named tabControl you could set the selectedIndex from different methods, i use following methods mostly.

codebehind:

tabControl.SelectedIndex = 0; // Sets the focus to first tabpanel

clientside:

First, put the following javascript in your aspx/ascx file:

<script type="text/javascript">
function SetActiveTab(tabControl, activeTabIndex) {
    var activeTab = tabControl.GetTab(activeTabIndex);
    if(activeTab != null)
        tabControl.SetActiveTab(activeTab);
}</script>

Then add following clientside event to prefered controller:

OnClientClick="function(s, e) { SetActiveTab(tabControl, 0);
QuBaR