我试图通过创建除MyPage.aspx和MyPage.aspx.cs以及MyPage.aspx.designer.cs之外的第三个部分文件来添加一些非生产测试代码.我调用了我的第三个文件MyPage.aspx.TEST.cs
在部分文件MyPage.aspx.TEST.cs中,我写了以下内容:
protected override void OnInit(EventArgs e)
{
Page.LoadComplete += RunTest;
base.OnInit(e);
}
//Assert.
public void RunTest(object sender, EventArgs e)
{
//Clever assertions
}
Run Code Online (Sandbox Code Playgroud)
代码编译然后我反编译代码就在那里,我可以看到OnInit覆盖和RunTest方法.
但是当我执行页面时,事件不会注册,也不会运行,也不能设置断点.
我将该代码从MyPage.aspx.TEST.cs部分类中移出到MyPage.aspx.cs部分文件和事件寄存器中并执行.奇怪的是,当我反编译程序集并执行diff时,该类似乎反编译为相同的代码.
可能不相关的可能线索:
这很奇怪,我刚刚做了相同的实验,所有事件都被触发,我有相同的条件,Web应用程序,autoeventwireup = true
您是否从另一个基页继承?
这是我的部分课程:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
所有事件都有效,如果我取消注释,//throw new NotImplementedException();我会按预期得到异常。
请尝试以下操作:
Page.LoadComplete += RunTest;为this.LoadComplete += RunTest;| 归档时间: |
|
| 查看次数: |
54 次 |
| 最近记录: |