views:

403

answers:

1

When I've built applications in the past I've used AutoEventWireup to handle the page events for me. From what I've read this incurs a significant performance cost and I'd like to do it manually in my current application.

What is the correct place to set up the event handlers?

My initial thought was to just set up a constructor in my code behind file and do it there but I'm assuming that the auto generated portion of the partial class already contains a constructor that I'd be overriding.

I'm sorry to ask here on such a simple question. It seems like this should be easily searchable but I'm just not finding the answer I need. Thanks in advance for the help.

+1  A: 
protected override void OnPreInit(EventArgs e)
{
    base.OnPreInit(e);
    Load += new EventHandler(Page_Load);
}

For controls it's OnInit, since they have no OnPreInit. To be honest I've used OnInit for pages as well in the past :)

Of course, you could just do the above for all the events you need for your page, and define no event handlers whatsoever.

Thorarin
Thank you very much!
apocalypse9