Note: This method is new in the .NET Framework version 2.0.
Sets the browser focus to the specified control.
Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
Visual Basic (Declaration)
Public Sub SetFocus ( _
control As Control _
)
Dim instance As Page
Dim control As Control
instance.SetFocus(control)
public void SetFocus (
Control control
)
public:
void SetFocus (
Control^ control
)
public void SetFocus (
Control control
)
public function SetFocus (
control : Control
)
Parameters
- 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. |
The following code example sets the focus to the second text box on a Web page.
<%@ page language="VB" %>
<script runat="server">
Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
SetFocus(focusHere)
End Sub
</script>
<html>
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:textbox id="default" runat="server" /><br />
<asp:textbox id="focusHere" runat="server" />
</form>
</body>
</html>
<%@ page language="C#" %>
<script runat="server">
void Page_Init(object sender, EventArgs e)
{
SetFocus(focusHere);
}
</script>
<html>
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:textbox id="default" runat="server" /><br />
<asp:textbox id="focusHere" runat="server" />
</form>
</body>
</html>
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
.NET Framework
Supported in: 2.0