如何在页面基类中执行Page_Load()?
我有以下 PerformanceFactsheet.aspx.cs 页面类
public partial class PerformanceFactsheet : FactsheetBase
{
protected void Page_Load(object sender, EventArgs e)
{
// do stuff with the data extracted in FactsheetBase
divPerformance.Controls.Add(this.Data);
}
}
,其中 FactsheetBase 定义为
public class FactsheetBase : System.Web.UI.Page
{
public MyPageData Data { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
// get data that's common to all implementors of FactsheetBase
// and store the values in FactsheetBase's properties
this.Data = ExtractPageData(Request.QueryString["data"]);
}
}
问题是 FactsheetBase 的 Page_Load 未执行。
谁能告诉我我做错了什么?有没有更好的方法来获得我想要的结果?
谢谢
I have the following PerformanceFactsheet.aspx.cs page class
public partial class PerformanceFactsheet : FactsheetBase
{
protected void Page_Load(object sender, EventArgs e)
{
// do stuff with the data extracted in FactsheetBase
divPerformance.Controls.Add(this.Data);
}
}
where FactsheetBase is defined as
public class FactsheetBase : System.Web.UI.Page
{
public MyPageData Data { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
// get data that's common to all implementors of FactsheetBase
// and store the values in FactsheetBase's properties
this.Data = ExtractPageData(Request.QueryString["data"]);
}
}
The problem is that FactsheetBase's Page_Load is not executing.
Can anyone tell me what I'm doing wrong? Is there a better way to get the result I'm after?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
嗯,我可能错了,但我相信这是由于继承造成的:您正在重写派生类中的 FactsheetBase Page_Load 方法。
为了让它执行,你应该做一些类似的事情
编辑:n8wrl 肯定给了你一个更干净的解决方案(我不是 ASPX 程序员)。
Uhm, I maybe wrong, but I believe this is due to inheritance: you are overwriting the FactsheetBase Page_Load method in the derived class.
In order to have it executed you should do something like
EDIT: n8wrl definitely gave you a cleaner solution (I am not a ASPX programmer).
试试这个
try this one
试试这个:
try this one:
使页面加载公开,并从其他页面以如下方式调用它:
Make the page load public, and call it in a manner like this from the other page:
我们遇到了类似的问题,您所需要做的就是在构造函数中注册处理程序。 :)
另一种方法是重写 OnLoad(),但这种方法不太受欢迎。
We faced the similar problem, All you need to do is just register the handler in the constructor. :)
Another approach would be to override OnLoad() which is less preferred.
替代 Page_Load() 方法,重写 OnLoad() 并调用 PerformanceFactsheet 中的 base.OnLoad()
Instead of a Page_Load() method, override OnLoad() and call base.OnLoad() in PerformanceFactsheet