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:
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:
public partial class _Default
{
protected override void OnInit(EventArgs e)
{
this.LoadComplete += RunTest;
this.Load += new EventHandler(_Default_Load);
base.OnInit(e);
}
void _Default_Load(object sender, EventArgs e)
{
//throw new NotImplementedException();
}
void RunTest(object sender, EventArgs e)
{
//throw new NotImplementedException();
}
protected override void OnPreRender(EventArgs e)
{
this.Response.Write("omfgggg");
this.lblMyMessageTest.Text = "omfg2";
base.OnPreRender(e);
}
}
All the events works, if I uncomment the //throw new NotImplementedException();
I get the exception as expected.
Try the following:
Page.LoadComplete += RunTest;
to this.LoadComplete += RunTest;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With