System.Web.UI Namespace Page Class
.NET Framework version 2.0
Sets the browser focus to the control with the specified identifier.
[ VB ]
Public Sub SetFocus (
clientId As String
)
[ C# ]
public void SetFocus (
String clientId
);
[ C++ ]
public: void SetFocus (
String^ clientId
);
[ JScript ]
public function SetFocus (
clientId : String
);
- clientId
- The ID of the control to set focus to.
Use the SetFocus method to make the control with the specified ID string the active control in 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 clientId 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.ClientID );
}
Sub Page_Init ( sender As Object, e As EventArgs )
SetFocus ( searchBox.ClientID )
End Sub 'Page_Init |
|
C# |
VB |
Page Members Page.SetFocus Overload List