I am using C#. By default, when I add a web form in Visual Studio 2008 with or without a master page, the AutoEventWireup attribute is set to true in the page directive. This attribute is also set to true inside the master page master directive.
What value should I have AutoEventWireup set to (true/false)?
What are the pros and cons of both values?
Any help is greatly appreciated.
Thank you.
That is a way of automatically wiring up event handlers to events based on naming conventions that Microsoft has setup.
The way this is implemented is with reflection, if I remember correctly. At runtime, ASP.NET will inspect your class, look for methods with signatures that match the naming convention expected, and then wire those up as handlers for their respective events.
That said, the pros are that it is a standard approach and saves you the trouble of wiring up the event handlers yourself. A perceived ‘con’ would be that it takes an extra step (reflection) that costs a bit more than if you were to do it yourself.
For the most part, the reflection ‘cost’ is so little that it really isn’t worth mentioning, but it is important to be aware of what is happening under the covers.