Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 重写onLoad(e)的重写,但调用最低的基本实现_C#_Asp.net_Overriding - Fatal编程技术网

C# 重写onLoad(e)的重写,但调用最低的基本实现

C# 重写onLoad(e)的重写,但调用最低的基本实现,c#,asp.net,overriding,C#,Asp.net,Overriding,我在重写方法时遇到问题。我已经用自定义代码创建了一个基类,希望在OnLoad事件期间运行该基类。此重写方法中的代码应用于从其继承的90%的页面,但在少数页面上,我需要重写该重写。我的问题是,我仍然需要运行System.Web.UI.Page的OnLoad实现。如果我在第二个类中包含base.OnLoad(e)行(见下文),它将调用BasePageEdit的逻辑,但是如果我删除它,则永远不会调用Page_加载事件。如何跳过BaseEditPage中的逻辑,仍然可以从System.Web.UI.Pa

我在重写方法时遇到问题。我已经用自定义代码创建了一个基类,希望在OnLoad事件期间运行该基类。此重写方法中的代码应用于从其继承的90%的页面,但在少数页面上,我需要重写该重写。我的问题是,我仍然需要运行System.Web.UI.Page的OnLoad实现。如果我在第二个类中包含base.OnLoad(e)行(见下文),它将调用BasePageEdit的逻辑,但是如果我删除它,则永远不会调用Page_加载事件。如何跳过BaseEditPage中的逻辑,仍然可以从System.Web.UI.Page获得功能

public class BasePageEdit : System.Web.UI.Page
{
    protected override void OnLoad(EventArgs e)
    {
     // I need this to raise the Page_Load Event!
     base.OnLoad(e); // Calls System.Web.UI.Page OnLoad Event which I want.

    // Logic that I want to run in ADDITION to base Implementation;

    }

    // Other classes and methods;
}

public class WebPageThatNeedsSpecialOnLoadImplementation : BasePageEdit
{
     protected override void OnLoad(EventArgs e)
     {
     // I need this to raise the Page_Load Event!
     base.OnLoad(e); // If I include this, it runs the BasePageEdit, I don't want that...
     // But I still need to run the System.Web.UI.Page onLoad event or Page_Load will not be called.

     // Logic that I want to run INSTEAD of the logic from the override from BasePageEdit.
     }
}
非常感谢你的Slaks!我正在编辑我的问题,以显示我是如何实现的,以便其他查看此帖子的人可以选择同样的方式实现

public class BasePageEdit : System.Web.UI.Page
{
    protected override void OnLoad(EventArgs e)
    {
    BasePage_OnLoad(e);

    // Logic that I want to run in ADDITION to base Implementation;

    }

    protected virtual void BasePage_OnLoad(EventArgs e)
    {
         base.OnLoad(e);
    }

    // Other classes and methods;
}

public class WebPageThatNeedsSpecialOnLoadImplementation : BasePageEdit
{
     protected override void OnLoad(EventArgs e)
     {
         BasePage_OnLoad(e);

     // Logic that I want to run INSTEAD of the logic from the override from BasePageEdit.
     }
}
你不能那样做

但是,您可以在
BasePageEdit
中创建一个新方法,它只调用它的
base.OnLoad
,然后直接从派生类调用它。

您不能这样做


但是,您可以在
BasePageEdit
中创建一个新方法,只调用它的
base.OnLoad
,然后直接从派生类调用它。

这是不可能的;如果您在许多页面上有不可能的要求,则创建另一个基类;如果您在许多页面上有此要求,请创建另一个基类