System.Web.UI Namespace Page Class
.NET Framework version 2.0
Sets the browser focus to the specified control.
[ VB ]
Public Sub SetFocus (
control As Control
)
[ C# ]
public void SetFocus (
Control control
);
[ C++ ]
public: void SetFocus (
Control^ control
);
[ JScript ]
public function SetFocus (
control : Control
);
- control
- The control to receive focus.
Use the SetFocus method to make the specified control the active control on the Web page displayed by the browser. The SetFocus method must be called before the page is prepared for rendering to the client in the PreRender event.
NOTE: The SetFocus method will work only on browsers supporting ECMAScript version 1.3 or later.
Exception Type |
Condition |
ArgumentNullException |
Thrown if control is a null reference ( Nothing in Visual Basic ). |
InvalidOperationException |
Thrown if SetFocus is called when the control is not part of a Web Forms page.
or
SetFocus is called after the PreRender event. |
The following example demonstrates using the SetFocus method.
NOTE: This example shows how to use one of the overloaded versions of SetFocus. For other examples that might be available, see the individual overload topics.
void Page_Init ( object sender, EventArgs e ) {
SetFocus ( searchBox );
}
Sub Page_Init ( sender As Object, e As EventArgs )
SetFocus ( searchBox )
End Sub 'Page_Init |
|
C# |
VB |
Page Members Page.SetFocus Overload List