asp.net.ph

Page.SetFocus Method ( Control )

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

Parameters

control
The control to receive focus.

Remarks

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.

Exceptions


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.

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