Conversion to Web Application Project Resets AutoEventWireup

Posted on July 15, 2006  |  

Posted in Development

3 comments

Suppose you have an ASP.NET 1.x project and you want to migrate it to 2.0. You load it up in Visual Studio 2005 and run the conversion wizard.

Convert to a Web Application

Next, you decide to convert it to a Web Application Project (WAP), which I always recommend over the web site model. Right click the project name and select “Convert to Web Application.”

Note this: in 1.x, the default Web Form template has AutoEventWireup="false". However, during the conversion to WAP this attribute is flipped to “true” on all pages! I had to track down every single page where this conversion took place and reset this attribute.

Also to note is that every new Web Form under WAP has AutoEventWireup="true" set by default.

Why Bother?

What’s the big deal with automatic event wire-up?

  1. I don’t like guesswork of naming event handlers. Is it Page_Load or Page_OnLoad? (See an earlier post on this.)
  2. The compiler does not tell you if you misspelled these names.
  3. I’m just not comfortable with event handlers pulled out of thin air; I’d rather have them wired explicitly.
  4. Finally, this automagic stuff does not come for free. Why would I incur the overhead of reflection if I don’t even need it?

3 comments

James Newton-King
on July 15, 2006

Are you sure the 'automagic' stuff is done with reflection? I would have thought the ASP.NET compiler would be able to figure that sort of stuff out and output code when the page was first hit.


scottgu
on July 15, 2006

Event wire-up is done via reflection, but the type-descripters are cached (so the lookup is one time only).

From a performance measurement perspective, there is no difference between autoeventwireup=true/false. That is one reason we switched to it as the default with VS 2005 Web App Projects.

Hope this helps,

Scott


Frans Bouma
on July 16, 2006

Not only is the setting flipped, but if you still have eventhandlers bound manually in the 1.x method in the code behind, it can be you get events handled twice. Be aware of that too.