Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have Tab Panel control .. I want to set focus on textbox from second tab of this control when second tab is selected .. how can i do that?
Posted
Comments
VedPrakash(Developer) 2-Jul-13 10:09am    
Please elaborate your question and if possible then paste your code to give correct support.
Sergey Alexandrovich Kryukov 2-Jul-13 10:26am    
Click Improve question and improve it. What tab? Where? Why it's a problem? What did you try so far? Any code sample?
—SA

Hi!

Go to your Tab panel Events, and choose SelectedIndexChanged.
Double click, and now you are in:

C#
private void TabControl1_SelectedIndexChanged(Object sender, EventArgs e) {
    // Here we check if selected index is Second Tab
    if(tabPanel.SelectedIndex == 1)
    {
        // Set focus on text box you need
        textBox.Select();
    }
}


Otherwise, you can use the SelectedTab property of Tab panel, that return you a TabPage, and then you can check by name:

C#
tabPanel.SelectedTab.Name == "Second Tab";
 
Share this answer
 
Solution

There is an event in Ajax TabContainer Control named as OnClientActiveTabChanged, which gets fired when you click on any Tab.
Quote:
OnClientActiveTabChanged - The name of a javascript function to attach to the client-side tabChanged event
So, you can specify the javaScript function, which you want to call, when any TabPanel is clicked.
HTML
<ajaxToolkit:TabContainer runat="server"
        OnClientActiveTabChanged="ClientFunction"


Now on that javaScript function, try to set focus of TextBox like below.
JavaScript
function ClientFunction()
{
    document.getElementById('TextBoxID').focus()
}


Demo

You can check how this Event works. Refer first Demo in Tabs Demonstration[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900