选择第二个选项卡时如何在文本框上设置焦点? [英] How to set focus on text box when second tab is selected ?
问题描述
我有Tab Panel控件..当我选择第二个标签时,我想从该控件的第二个标签设置焦点文本框..我该怎么做?
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?
推荐答案
嗨!
转到你的标签面板事件,然后选择SelectedIndexChanged。
双击,现在你进入:< br $>
Hi!
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
textBox.Select();
}
}
否则,您可以使用Tab的 SelectedTab 属性面板,返回一个TabPage,然后你可以按名称检查:
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";
解决方案
中有一个事件Ajax TabContainer
控件名为OnClientActiveTabChanged
,当你点击任何标签时会被触发。
Solution
There is an event inAjax TabContainer
Control named asOnClientActiveTabChanged
, which gets fired when you click on any Tab.
OnClientActiveTabChanged - 要附加到客户端tabChanged事件的javascript函数的名称
OnClientActiveTabChanged - The name of a javascript function to attach to the client-side tabChanged event
因此,您可以指定要调用的 javaScript
函数点击任何 TabPanel
。
So, you can specify the javaScript
function, which you want to call, when any TabPanel
is clicked.
<ajaxToolkit:TabContainer runat="server"
OnClientActiveTabChanged="ClientFunction"
现在在 javaScript
函数上,尝试设置焦点 TextBox
如下所示。
Now on that javaScript
function, try to set focus of TextBox
like below.
function ClientFunction()
{
document.getElementById('TextBoxID').focus()
}
演示
您可以查看此活动的工作原理。请参阅选项卡演示中的第一个演示[ ^ ]
Demo
You can check how this Event works. Refer first Demo in Tabs Demonstration[^]
这篇关于选择第二个选项卡时如何在文本框上设置焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!