I can use both in the code behind:
SetFocus() - "Sets the browser focus to the specified control."
Focus() - "Sets input focus to a control."
In practice, what's the difference?
Thanks!
Page.SetFocus
can accept a control's client ID as a string instead of a reference to the control itself, which may be useful if you can't get a reference to the control to call its Focus method.
control.Focus()
is identical to Page.SetFocus(control)
. In fact, all is does is call SetFocus...
public virtual void Focus()
{
this.Page.SetFocus(this);
}
From msdn :
To set focus on an ASP.NET Web server control
Call the control's Focus method.
-or-
Call the page's SetFocus method, passing it the ID of the control on which you want to set focus.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.