Skip navigation.

Book Review: Applying Domain-Driven Design and PatternsAll recent postsPassing Values Between Pages in ASP.NET 1.x and 2.0

Conversion to Web Application Project Resets AutoEventWireup

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?

Comments

Comment permalink 1 James Newton-King |
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.
Comment permalink 2 scottgu |
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
Comment permalink 3 Frans Bouma |
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.

Emails and Notifications

Would you like to be notified when somebody responds to this post?  Would you like to have these comments emailed to you?

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):