PagesSection.AutoEventWireup 속성

정의

ASP.NET 페이지의 이벤트가 이벤트 처리 함수에 자동으로 연결되는지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool AutoEventWireup { bool get(); void set(bool value); };
[System.Configuration.ConfigurationProperty("autoEventWireup", DefaultValue=true)]
public bool AutoEventWireup { get; set; }
[<System.Configuration.ConfigurationProperty("autoEventWireup", DefaultValue=true)>]
member this.AutoEventWireup : bool with get, set
Public Property AutoEventWireup As Boolean

속성 값

trueASP.NET 페이지의 이벤트가 이벤트 처리 함수에 자동으로 연결되면 이고, 그렇지 않으면 . false 기본값은 true입니다.

특성

예제

다음 코드 예제에서는 코드에서 속성을 설정하거나 읽는 AutoEventWireup 방법을 보여 있습니다.

// Get the current AutoEventWireup property value.
Console.WriteLine(
    "Current AutoEventWireup value: '{0}'",
    pagesSection.AutoEventWireup);

// Set the AutoEventWireup property to false.
pagesSection.AutoEventWireup = false;
' Get the current AutoEventWireup property value.
Console.WriteLine( _
    "Current AutoEventWireup value: '{0}'", _
    pagesSection.AutoEventWireup)

' Set the AutoEventWireup property to false.
pagesSection.AutoEventWireup = False

다음 예제에서는 페이지 이벤트에 AutoEventWireup 자동으로 연결 되는 경우 메서드 서명의 두 가지 형태를 보여 줍니다 true.

<%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>
// This method will be automatically bound to the Load event
// when AutoEventWireup is true.
protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("Hello world");
}
// This method will be automatically bound to the Load event 
// when AutoEventWireup is true only if no overload having 
// object and EventArgs parameters is found.
protected void Page_Load()
{
    Response.Write("Hello world");
}
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
' This method will be automatically bound to the Load event
' when AutoEventWireup is true.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Response.Write("Hello world")
End Sub
' This method will be automatically bound to the Load event 
' when AutoEventWireup is true only if no overload having 
' object and EventArgs parameters is found.    
Protected Sub Page_Load()
    Response.Write("Hello world")
End Sub

다음 예제에서는 다음과 같은 경우 AutoEventWireupfalse이벤트를 명시적으로 연결하는 방법을 보여 줍니다.

// Following are three alternative ways of binding an event
// handler to an event when AutoEventWireup is false.  For
// any given event do this binding only once or the handler
// will be called multiple times.

// You can wire up events in the page's constructor.
public _Default()
{
    Load += new EventHandler(Page_Load);
}

// You can override the OnInit event and wire up events there.
protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    Load += new EventHandler(Page_Load);
}

// Or you can override the event's OnEventname method and
// call your handler from there.  You can also put the code
// execute when the event fires within the override method itself.
protected override void OnLoad(EventArgs e)
{
    Page_Load(null, null);
    base.OnLoad(e);
}

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("Hello world");
}
' The Handles keyword binds Page_Load to the Load event.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Response.Write("Hello world")
End Sub

설명

이 경우 AutoEventWireuptrueASP.NET 이벤트 처리기를 페이지 이벤트(예: Load.)에 명시적으로 바인딩할 필요가 없습니다.

이 경우 AutoEventWireupfalse메서드에 이벤트를 명시적으로 바인딩해야 합니다. 예를 들어 페이지에 대한 코드에 메서드가 있는 경우 Page_Load 다음 예제에서와 같은 코드를 작성하는 경우에만 이벤트에 대한 응답으로 Load 메서드가 호출됩니다(Visual Basic의 Handles 문과 C#의 이벤트 처리기 코드 참조).

Partial Class AutoEventWireupExample
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles Me.Load
        Response.Write("Executing Page_Load")
    End Sub
End Class
public partial class AutoEventWireupExample : System.Web.UI.Page
{
    protected void Page_Load(object sender, System.EventArgs e)
    {
        Response.Write("Executing Page_Load");
    }
    override protected void OnInit(EventArgs e)
    {
        this.Load += new System.EventHandler(this.Page_Load);
    }
}

이 경우 AutoEventWireuptrue처리기는 해당 이름 및 서명에 따라 런타임에 이벤트에 자동으로 바인딩됩니다. 각 이벤트에 대해 ASP.NET 패턴 Page_이벤트 이름(예: Page_Load 또는 Page_Init)에 따라 이름이 지정된 메서드를 검색합니다. ASP.NET 일반적인 이벤트 처리기 서명(즉, 지정 및 Object 매개 변수)이 있는 오버로드를 먼저 확인합니다EventArgs. 이 서명이 있는 이벤트 처리기를 찾을 수 없는 경우 ASP.NET 매개 변수가 없는 오버로드를 확인합니다.

이 경우 AutoEventWireupfalse앞의 예제와 같이 이벤트 처리기를 이벤트에 명시적으로 바인딩해야 합니다. 이 경우 메서드 이름은 패턴을 따를 필요가 없습니다.

기본값은 true 지시문에 AutoEventWireup 지정되지 않은 경우 @ Page 입니다. Visual Studio는 코드 숨김 파일을 만들 때 자동으로 특성을 포함합니다. C#으로 작성된 ASP.NET 페이지의 경우 Visual Studio는 값을 true.로 설정합니다. Visual Basic의 경우 Visual Studio는 처리기가 이벤트 처리기를 생성할 false 때 Visual Studio에서 자동으로 삽입하는 Handles 키워드를 사용하여 이벤트에 바인딩되기 때문에 값을 설정합니다. 설정 AutoEventWireuptrue하면 Handles 키워드를 생략하거나 제거할 수 있습니다.

성능이 AutoEventWireup 주요 고려 사항인지 설정 true 하지 마세요. 자동 이벤트 와이어업을 사용하도록 설정하면 ASP.NET 15~30번 사이에 이벤트를 메서드와 일치시키려고 시도해야 합니다.

이벤트에 이벤트 처리기를 바인딩하는 방법은 다음과 같습니다.

  • 설정 AutoEventWireuptrue하면 페이지에 이벤트 처리기도 수동으로 연결하지 않도록 해야 합니다. 이렇게 하면 처리기가 두 번 이상 호출될 수 있습니다.

  • 자동 바인딩은 페이지의 컨트롤에 대한 이벤트가 아니라 페이지 이벤트에 대해서만 수행됩니다.

  • 처리기에 이벤트를 바인딩하는 대신 페이지 또는 컨트롤의 On 메서드를 재정 의할 수 있습니다.

적용 대상