asp.net.ph

Page.SetFocus Method ( String )

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

Parameters

clientId
The ID of the control to set focus to.

Remarks

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.

Exceptions


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.

Example

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 );
}
  C# VB

See Also

Page Members   Page.SetFocus Overload List Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph