如何在页面的基类执行的Page_Load()? [英] How to Execute Page_Load() in Page's Base Class?
本文介绍了如何在页面的基类执行的Page_Load()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下PerformanceFactsheet.aspx.cs页面类
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);
}
}
在这里FactsheetBase被定义为
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"]);
}
}
问题在于FactsheetBase的Page_Load中不执行
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?
感谢
推荐答案
我们所面临的类似问题,所有你需要做的就是注册在构造函数中的处理程序。 :)
We faced the similar problem, All you need to do is just register the handler in the constructor. :)
public class FactsheetBase : System.Web.UI.Page
{
public FactsheetBase()
{
this.Load += new EventHandler(this.Page_Load);
}
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"]);
}
}
另一种方法是为覆盖的OnLoad()这是少preferred。
Another approach would be to override OnLoad() which is less preferred.
public class FactsheetBase : System.Web.UI.Page
{
public FactsheetBase()
{
}
public MyPageData Data { get; set; }
protected override void OnLoad(EventArgs e)
{
//your code
// get data that's common to all implementors of FactsheetBase
// and store the values in FactsheetBase's properties
this.Data = ExtractPageData(Request.QueryString["data"]);
base.OnLoad(e);
}
}
这篇关于如何在页面的基类执行的Page_Load()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文