将焦点设置到文本框,在ASP.NET登录控件的页面加载 [英] Set focus to textbox in ASP.NET Login control on page load
本文介绍了将焦点设置到文本框,在ASP.NET登录控件的页面加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将焦点设置到用户名文本框这是一个ASP.NET登录控件中。
我试图做这几种方式,但没有似乎工作。页面加载,但不会控制。
下面是code我试过。
SetFocus的(this.loginForm.FindControl(用户名));
和
文本框TBOX =(文本框)this.loginForm.FindControl(用户名);
如果(TBOX!= NULL)
{
tbox.Focus();
} //如果
解决方案
您的网页上使用一个ScriptManager?如果是这样,请尝试以下操作:
公共无效SetInputFocus()
{
文本框TBOX = this.loginForm.FindControl(用户名)的文本框;
如果(TBOX!= NULL)
{
ScriptManager.GetCurrent(this.Page).SETFOCUS(TBOX);
}
}
更新:之前从未使用过的多视点,但试试这个:
保护无效MultiView1_ActiveViewChanged(对象发件人,EventArgs的发送)
{
SetInputFocus();
}
I am trying to set the focus to the user name TextBox which is inside an ASP.NET Login control.
I have tried to do this a couple of ways but none seem to be working. The page is loading but not going to the control.
Here is the code I've tried.
SetFocus(this.loginForm.FindControl("UserName"));
And
TextBox tbox = (TextBox)this.loginForm.FindControl("UserName");
if (tbox != null)
{
tbox.Focus();
} // if
解决方案
Are you using a ScriptManager on the Page? If so, try the following:
public void SetInputFocus()
{
TextBox tbox = this.loginForm.FindControl("UserName") as TextBox;
if (tbox != null)
{
ScriptManager.GetCurrent(this.Page).SetFocus(tbox);
}
}
Update: Never used a multiview before, but try this:
protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
{
SetInputFocus();
}
这篇关于将焦点设置到文本框,在ASP.NET登录控件的页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文