views:

581

answers:

2

Using C#, there is a web form with many controls where the AutoEventWireup is set to false. This forces you to initialize the handlers that you need in the ctor or by overriding OnInit.

What about the handling needed for the controls on the page? Adding button Click's, and SelectedIndexChanged's for dropdowns and listboxes, not to many several GridView events, etc.

If AutoEventWireup was set to true, it would affect performance since all events for all controls (inc. the Page) would get wired-up behind the scenes, even all of those you didn't need.

With AutoEventWireup set to false, is it proper to have a dozen or two event subscriptions in the ctor/OnInit? (this.Load+=...this.GridView1.Sorted+=...this.Button1.Click+=...etc.)

+2  A: 

Yes, you will need to manually wire up all events yourself if you set AutoEventWireup to false. The OnInit method is a good palce to wire these event handlers and you should have as many event subscriptions in there as you need for the controls on your page.

AutoEventWireup is a nice idea but is slow and is also a bit magical. I find it is much better to explicitly do the wireups yourself.

Andrew Hare
+1 for petition to officially change it to AutoEventWireUpWithUnicorns
Chad Grant
+1  A: 

AutoEventWireUp only automatically wires up certain built-in Page or control level events, not every event of every control on your Page.

For a list, see Simon's answer to this question.

Cerebrus