How can a breakpoint on Page_Load NOT get hit?

A couple possible answers here:

  1. You aren't actually going to the page you think you are. See Why is Page_Load not firing after coming back from another page using ASP.NET - ergo epic embarrassment :)

  2. The browser you are using has aggressively cached the page and isn't loading it. Make sure your browser of choice has ALL caching disabled.

  3. The page is inheriting from a base class which got rid of the onload event.

  4. The markup page is inheriting from a class different from the one you expect. (Happens a lot in copy / paste situations.)


In order for Page_Load to be executed, one of the following must be true:

  • You must have AutoEventWireup="true" in the @Page directive of the aspx page.

  • The event handler must be wired up explicitly, normally in OnInit

UPDATE

As pointed out in @bzlm's comment, the default for AutoEventWireup is "true", so in fact it will be executed also if the AutoEventWireup attribute is missing from the page directive.

Older versions of Visual Studio (2003 certainly, and maybe 2005) used to explicitly wireup events, and recommend to set AutoEventWireup to false.

From what I can see, I don't think this is true any more. The explicit wireup was done with the line:

this.Load += new System.EventHandler(this.Page_Load);

in the InitializeComponent method that was generated by the designer and called from the OnInit method.


if you have AutoEventWireup="false" in your <% @Page %> directive the Page_Load method will not be attached to the Page.Load event.