views:

39

answers:

2

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!

+1  A: 

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.

karim79
In other words, the Focus method is on the control level whereas the SetFocus method is on the page level and must know what to set focus on.
npsken
+1  A: 

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);
}
stevemegson