Let's see what happens when it's values changes between true and false.
Case: AutoEventWireUp="true"
This is the default value for AutoEventWireUp attribute in C# and False for a VB.Net form so be specific while answering to somebody. You should know his/her context. When AutoEventWireup is true, all we need to do is follow the method naming convention of Page_EventToHandle. The ASP.NET runtime will automatically find and fire the method for the appropriate event.
One more point for ASP.Net life cycle and events; see here for details. Now look at the syntax of let's say the Page_Load event. Here Load is the method that raises the event.
protected void Page_Load(object sender, EventArgs e)
{
}
And
protected void Page_Load()
{
}
Both are valid because I think there must be two delegates defined to handle the event with these two different handlers.
Now People say that from a performance point of view set the value of AutoEventWireUp to "false". Why?
Reason is here:
- Page_PreInit
- Page_Init
- Page_InitComplete
- Page_PreLoad
- Page_Load
- Page_LoadComplete
- Page_DataBind
- Page_SaveStateComplete
- Page_PreRender
- Page_PreRenderComplete
- Page_Unload
- Page_Error
- Page_AbortTransaction
- Page_CommitTransaction
This is the list of all some page events that occur during the page life cycle (some list items may be different from this list since it depends on the ASP.Net version). So what happens is that the runtime looks for these handlers when AutoEventWireUp="true". And since it supports both argument and non-argumented handlers. So the number of lookup calls are doubled. Now you may be concerned about performance if your site is having thousands of requests at a time and your runtime is searching for this stuff in between.
Case 2: AutoEventWireUp="false"
Now since the value is set to false the runtime won't do a lookup for the significant handlers. So now you have to explicitly bind the handlers with events.
Question: When and where will I bind the page events to its Handlers?
The answer is in the constructor of your class of the ASP.Net page.
public partial class _Default : Page
{
public _Default() // ctor
{
Load += new EventHandler(Page_Load);
PreInit += new EventHandler(Page_PreInit);
}
protected void Page_Load(object sender, EventArgs e)
{
// ...
}
protected void Page_PreInit(object sender, EventArgs e)
{
// ...
}
}
Now you should have a look at this attribute when you are going to work on any ASP.Net WebApplication.
Happy Coding....

Amit ChoudharyPosted Apr 22, 2011, 2:16 AM
Thanks Karthik :)
Amit ChoudharyPosted Apr 22, 2011, 2:15 AM
I agree Suthish.. It won't have any big impact on performance, but why would you burn your CPU cycles in searching of matching delegates for these events if you are using only 2-3 of them. Hope this make sense to you. Microsoft always focus on user experience so it may be one of the point they ignored it in c#. but if you look at VB.Net template of asp.net forms you'll find it automatically set to false as VB support Handles for events. PS: We've seen the outcome of VISTA OS :) best UI experience but Performance just thrown it out of market and hence the WIN 7 introduced n i love it cuz of performance.
Suthish NairPosted Apr 21, 2011, 7:19 AM
I think there is not much performance issue. There is no well documented saying why we do not use true or false. If anyone came up with actual numbers, please share. In VS 2003 it was default "false", but other releases uses "true", then why Microsoft doing this if actually a performance issue is there. Another good explanation: http://www.shiningstar.net/blog/AutoEventWireup.aspx
Karthikeyan AnbarasanPosted Apr 21, 2011, 7:14 AM
Good one man... Keep going!!!