I was trying to add some non-production test code by creating a 3rd partial file in addition to MyPage.aspx and MyPage.aspx.cs and MyPage.aspx.designer.cs. I called my third file MyPage.aspx.TEST.cs
In the partial file MyPage.aspx.TEST.cs, I wrote the following:
protected override void OnInit(EventArgs e)
{
Page.LoadComplete += RunTest;
base.OnInit(e);
}
//Assert.
public void RunTest(object sender, EventArgs e)
{
//Clever assertions
}
The code compiles and I then decompile the code and there it is, I can see the OnInit override and the RunTest method.
But when I execute the page, the event doesn’t register, nor run, nor can I set a breakpoint.
I move that code out of the MyPage.aspx.TEST.cs partial class into the MyPage.aspx.cs partial file and the event registers and is executed. Stranger, when I decompile the assembly, and do a diff, the class appears to decompile to the same code.
Possible clues that may be unrelated:
- The page uses autoeventwireup=”true” (I still get the same behavior if I try to register my event my Page_LoadComplete)
- The application is a web application (i.e.uses a proj file)
- The partial file does compile (and if I introduce errors into the partial file, it will prevent compilation, so I know for sure that the partial file does get compiled)
- I get the same result using different events (PreRender, etc)
This is strange, I just made the same experiment and all the events are being fired, I have the same conditions, web application, autoeventwireup = true
Are you inheriting from another base page?
This is my partial class:
All the events works, if I uncomment the
//throw new NotImplementedException();I get the exception as expected.Try the following:
Page.LoadComplete += RunTest;tothis.LoadComplete += RunTest;