Page_Load isn’t a virtual method. What calls this method and how does it do it? Is it reflection or some other technique? Also how many events are handled this way?
Also is it preferable to handle things in an overloaded OnLoad or Page_Load? How are they different?
ASP.NET has a feature called “AutoEventWireup” – this feature allows you to create methods that have the
EventHandlersignature with names likePage_Loadand the runtime will wire up the event from the parent page to the method in your class. Basically the runtime does this on your behalf:Now it is better to disable AutoEventWireup and either create these event handlers yourself in the pages
OnInitmethod or simply override the parent page’sOnLoadmethod.Edit (in response to the OP’s comment below): This process doesn’t cover button clicks and such but the process is similar.
In order for a method like
MyButton_Clickto work without you explicitly creating an event handler you would have to set theOnClickattribute on the control in the aspx file like this:This would prompt ASP.NET to create the button click delegate for you and attach it to the button’s
Clickevent.