Page::SetFocus Method (String)
Sets the browser focus to the control with the specified identifier.
Assembly: System.Web (in System.Web.dll)
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.
The SetFocus method will work only on browsers supporting ECMAScript version 1.3 or later.
The following code example sets the focus to the second text box on a Web page.
This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.