Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a breakpoint on Page_Load NOT get hit?

I have a breakpoint set on a page's Page_Load event that never gets hit. There are no warning or messages indicating the breakpoint may never be hit, it just never gets hit even though the page is loaded successfully.

After a successful login, the user is redirected to this page using the login control's DestinationPageUrl property. As mentioned above, I can login and get to this page so at least that part works.

If I set a breakpoint on the Page_Load event of the Login page (just plain old ASP.NET sample Web Application stuff here), the breakpoint will get hit. I can step into the code but the page_load event never gets hit and the page just appears. In this sequence, I step through the page_load events of the login.aspx and site.master but not the page_load I really want to see.

Any suggestions? Thanks!

like image 486
DenaliHardtail Avatar asked Apr 18 '11 18:04

DenaliHardtail


People also ask

What does setting a breakpoint do?

Breakpoints are very useful when debugging JavaScript — you basically set a point in your code where you would like execution of the code to pause. At this point you can do useful things like studying the value of different variables at that point, allowing you to work out why a problem is occurring.

Why breakpoint is not hitting with VS code?

If a source file has changed and the source no longer matches the code you're debugging, the debugger won't set breakpoints in the code by default. Normally, this problem happens when a source file is changed, but the source code wasn't rebuilt. To fix this issue, rebuild the project.

How do you stop a breakpoint?

To Disable All BreakpointsOn the Debug menu, click Disable All Breakpoints. On the toolbar of the Breakpoints window, click the Disable All Breakpoints button.


2 Answers

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.

like image 105
Joe Avatar answered Oct 17 '22 07:10

Joe


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.)

like image 41
NotMe Avatar answered Oct 17 '22 08:10

NotMe