- AutoEventWireup is a Boolean attribute that indicates whether events of a Web Forms page are autowired.
- The default value for
AutoEventWireup is TRUE, and can be set as follows:
- TRUE when event-autowiring is activated.
- FALSE when event-autowiring is not activated.
In Visual Basic .NET or in Visual Basic 2005, the designer performs this binding using the Handles keyword in the declaration of the event-handler method.
The following sample code illustrates the Handles keyword in Visual Basic .NET or in Visual Basic 2005:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
this.Load += new System.EventHandler(this.Page_Load);
AutoEventWireup attribute of the @ Page directive is set to TRUE (or if it is not specified because its default value is TRUE), the ASP.NET page framework automatically calls page event-handler methods.
For example, the Page_Init and Page_Load event-handler methods are explicitly called by the ASP.NET page framework, without using the Handles keyword or an explicit event delegate.
However, the drawback of using the AutoEventWireup attribute to automatically associate page events and their event-handler methods, is that event-handler methods must have standard, predefined names. This limits how you can name event-handler methods.
Visual Studio .NET and Visual Studio 2005 do not have the same limitation on method names. In Visual Studio .NET and in Visual Studio 2005, the default setting for AutoEventWireup is FALSE. Additionally, the designer always uses the Handles keyword or an explicit event delegate to bind events to their event-handler methods. As a result, you can use non-standard names for event-handler methods.
ConclusionWhen you explicitly set AutoEventWireup to TRUE, Visual Studio .NET or Visual Studio 2005, by default, generates code to bind events to their event-handler methods. At the same time, the ASP.NET page framework automatically calls the event-handler methods based on their predefined names. This can lead to the same event-handler method being called two times when the page runs. Therefore, Microsoft recommends that you always set AutoEventWireup to FALSE while working in Visual Studio .NET.
문서 ID: 814745 - 마지막 검토: 2008. 5. 13. - 수정: 1