我有以下业绩表.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的页面加载没有执行.

谁能告诉我我做错了什么吗?有没有更好的方法来获得我想要的结果?

谢谢

推荐答案

我们面临着类似的问题,你只需要做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"]);             
    } 
}

另一种方法是设置为override OnLoad(),这不太受欢迎.

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);
    }
}

Asp.net相关问答推荐

在Docker Windows中,ASP.NET核心容器在自定义端口8080上运行,但ASP.NET容器在固定端口80上运行

AJAX返回未定义、失败

如何使用 Get-Process powershell 命令通过端口号获取进程的 ID

您如何处理多个环境的多个 web.config 文件?

如何防止 IISExpress 和我的网站文件夹弄乱我的文档文件夹?

HttpRuntime.Cache[] 与 Application[]

如何将 JQuery 与母版页一起使用?

为什么微软决定支持 jQuery 如此重要?

在哪里可以记录 ASP.NET Core 应用程序的启动/停止/错误事件?

Azure Service Fabric 是否与 Docker 做同样的事情?

我可以根据角色隐藏/显示 asp:Menu 项吗?

如何判断 IIS 是处于 32 位还是 64 位模式

不支持关键字:服务器

stream.CopyTo - 文件为空.网

获取页面上特定类型的所有 Web 控件

我的 asp.net mvc Web 应用程序中的 OutputCache 设置.防止缓存的多种语法

通过 ASP.NET/C# 使用 Plupload

IIS 8.0 ASP.NET 和错误 500.19

根据条件更改 GridView 行 colored颜色

如何解决我的 ASP.Net MVC 应用程序中的 iisreset 后发生的 AntiForgeryToken 异常?