在asp.net中让控件获得焦点的方法
答1:
static public bool SetFocus(System.Web.UI.Control control)
{
if (HttpContext.Current.Request.Browser.JavaScript)
{
control.Page.RegisterStartupScript("SetFocus","<script language='javascript'>document.forms[0]." +
control.ClientID +".focus();</script>");
return true;
}
return false;
}
调用:
SetFocus(this.txtBoxName);
答2:
写在<body onload="document.form1.textbox1.focus();">
______________________________________________________________________________________________
答3:
static public bool SetFocus(System.Web.UI.Control control)
{
if (HttpContext.Current.Request.Browser.JavaScript)
{
control.Page.RegisterStartupScript("SetFocus","<script language='javascript'>document.forms[0]." +
control.ClientID +".focus();</script>");
return true;
}
return false;
}
调用:
SetFocus(this.txtBoxName);