Page.SetFocus 메서드

정의

브라우저 포커스를 지정된 컨트롤에 설정합니다.

오버로드

SetFocus(Control)

브라우저 포커스를 지정된 컨트롤에 설정합니다.

SetFocus(String)

브라우저 포커스를 지정된 식별자를 가진 컨트롤에 설정합니다.

SetFocus(Control)

브라우저 포커스를 지정된 컨트롤에 설정합니다.

public:
 void SetFocus(System::Web::UI::Control ^ control);
public void SetFocus (System.Web.UI.Control control);
member this.SetFocus : System.Web.UI.Control -> unit
Public Sub SetFocus (control As Control)

매개 변수

control
Control

포커스를 받을 컨트롤입니다.

예외

control이(가) null인 경우

컨트롤이 Web Forms 페이지에 속해 있지 않을 때 SetFocus(Control)가 호출된 경우

또는

SetFocus(Control)PreRender 이벤트 다음에 호출된 경우

예제

다음 코드 예제에서는 웹 페이지의 두 번째 텍스트 상자에 포커스를 설정합니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

<%@ page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    void Page_Init(object sender, EventArgs e)
    {
        SetFocus(focusHere);
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<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="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
        SetFocus(focusHere)
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<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>

설명

사용 된 브라우저에 SetFocus 의해 표시 된 웹 페이지에서 활성 컨트롤을 지정 된 컨트롤을 만들려면 메서드. SetFocus 이벤트에서 클라이언트 PreRender 에 렌더링할 페이지가 준비되기 전에 메서드를 호출해야 합니다.

참고

메서드는 SetFocus ECMAScript 버전 1.3 이상을 지원하는 브라우저에서만 작동합니다.

적용 대상

SetFocus(String)

브라우저 포커스를 지정된 식별자를 가진 컨트롤에 설정합니다.

public:
 void SetFocus(System::String ^ clientID);
public void SetFocus (string clientID);
member this.SetFocus : string -> unit
Public Sub SetFocus (clientID As String)

매개 변수

clientID
String

포커스를 설정할 컨트롤의 ID입니다.

예외

clientID이(가) null인 경우

컨트롤이 Web Forms 페이지에 속해 있지 않을 때 SetFocus(String)가 호출된 경우

또는

SetFocus(String)PreRender 이벤트 다음에 호출된 경우

예제

다음 코드 예제에서는 웹 페이지의 두 번째 텍스트 상자에 포커스를 설정합니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

<%@ page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    void Page_Init(object sender, EventArgs e)
    {
        SetFocus(focusHere.ClientID);
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<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="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
        SetFocus(focusHere.ClientID)
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head 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>

설명

메서드를 SetFocus 사용하여 지정된 ID 문자열이 있는 컨트롤을 브라우저에서 표시하는 웹 페이지의 활성 컨트롤로 만듭니다. SetFocus 이벤트에서 클라이언트 PreRender 에 렌더링할 페이지가 준비되기 전에 메서드를 호출해야 합니다.

참고

메서드는 SetFocus ECMAScript 버전 1.3 이상을 지원하는 브라우저에서만 작동합니다.

적용 대상