What is AutoEventWireup ?

How to use the AutoEventWireup attribute in ASP.NET c# vb.net

The ASP.NET page framework supports an automatic way to associate page events and methods. When a Page is requested, it raises various events which are considered to be part of it's lifecycle. AutoEventWireup is an attribute of the @ Page directive. The AutoEventWireup attribute may have a value of true or false.

The AutoEventWireUp property when True, automatically wires up some of these built-in events in the Page life cycle to their handlers. This means that you do not need to explicitly attach these events Examples of these built-in events would be Page_Init and Page_Load.

private void Page_Load(object sender, System.EventArgs e) { }

The value of AutoEventWireup = false means that your Page_Load event will not be automatically hooked to the page's Load event and so on for PreRender and the other page lifecycle events. It means in the constructor of your code-behind base class for the Page, you will have to manually do.

You can specify a default value of the AutoEventWireup attribute in several places:

  1. The Machine.config file
  2. The Web.config file
  3. Individual ASP.NET Web Forms (.aspx files)
  4. Web User Controls (.ascx files)

Example:

To change the value of the AutoEventWireup attribute in the individual ASP.NET Web Form, add the AutoEventWireup attribute to the @ Page directive, as follows:

<% @Page AutoEventWireup="true" %>
In Visual Studio What does AutoEventWireUp page property mean  ASP.NET c# vb.net

When you use Microsoft Visual Studio .NET, the value of the AutoEventWireup attribute is set to false and the designer automatically generates event handlers. If you do set AutoEventWireup to true, Visual Studio will generate code to bind the events and the page framework will automatically call events based on their names. This can result in the same event code being called twice when the page runs. As a consequence, you should always leave AutoEventWireup set to false when working in Visual Studio.

Disadvantage What is the AutoEventWireup attribute in ASP.NET c# vb.net

The disadvantage of the AutoEventWireup attribute is that it requires that the page event handlers have specific, predictable names. This limits your flexibility in how you name your event handlers. Therefore, in Visual Studio, the AutoEventWireup attribute is set to false by default and the designer generates explicit code to bind page events to methods.