What calls Page_Load and how does it do it?

ASP.NET has a feature called “AutoEventWireup” – this feature allows you to create methods that have the EventHandler signature with names like Page_Load and 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:

this.Load += this.Page_Load;

Now it is better to disable AutoEventWireup and either create these event handlers yourself in the pages OnInit method or simply override the parent page’s OnLoad method.

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_Click to work without you explicitly creating an event handler you would have to set the OnClick attribute on the control in the aspx file like this:

<asp:button 
    id="MyButton"
    onClick="MyButton_Click"
    runat="server" />

This would prompt ASP.NET to create the button click delegate for you and attach it to the button’s Click event.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)