Click here to Skip to main content
15,848,157 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?
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?


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

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

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

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

There is an event in Ajax TabContainer Control named as OnClientActiveTabChanged, which gets fired when you click on any Tab.
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.
<ajaxToolkit:TabContainer runat="server"

Now on that javaScript function, try to set focus of TextBox like below.
function ClientFunction()


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