This article describes the AutoEventWireup
- 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 Studio .NET or in Visual Studio 2005, events are bound to event-handler
methods using event delegates. If you use the Web Forms Designer
to design Web Forms, the designer automatically generates code to
bind events to their event-handler methods.
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.
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
In Visual C# .NET, the designer generates an explicit event delegate:
this.Load += new System.EventHandler(this.Page_Load);
The ASP.NET page framework supports an alternative mechanism that uses the AutoEventWireup
attribute of a Web Forms page to
automatically associate page events and event-handler methods. If the
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.
example, the Page_Init
event-handler methods are explicitly called by the ASP.NET page
framework, without using the Handles
keyword or an explicit event
However, the drawback of using the AutoEventWireup
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
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.
When 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.
For more information, visit the following MSDN Web