AutoEventWireup True Vs False

asp.net, visual-studio-2012

Solution

This setting is not about firing an event, but rather about binding handlers to standard page events. Compare these two snippets that illustrate handling `Load` event.

First, with `AutoEventWireup="true"`:

public class PageWithAutoEventWireup
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("Page_Load is called");
    }
}

Second, with `AutoEventWireup="false"`:

public class PageWithoutAutoEventWireup
{
    override void OnInit(EventArgs e)
    {
        this.Load += Page_Load;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("Page_Load is called");
    }
}

`Load` event will be fired by page and handled by your code in both cases. But in second case you have to sign up for the event explicitly, while in first case ASP.NET does everything for you.

Of course, the same goes for other page life-cycle events, like `Init`, `PreRender`, etc.

Problem

I am using Visual Studio 2012 professional edition. I do not see any difference over setting "true" versus "false" for AutoEventWireup property in page directive. All the time it is behaving as "true", Meaning - I set "false" and not binding events explicitly, but events are implicitly got bind. Please let me know if I am missing anything.

Original source