继承aspx页面中的抽象类

时间:2022-09-24 23:37:54

I know that multiple inheritance not supported in c#.But I want to inherit method from abstract class by keeping System.Web.UI.Page as it is.for example..

我知道c#中不支持多重继承。但是我想通过保持System.Web.UI.Page原样从抽象类继承方法。例如..

abstract class stuff1()
{
 public abstract void print();
}

in aspx page

在aspx页面中

 public partial class WebForm1: System.Web.UI.Page
 {
   //I want to implement print() method from abstract class here
  }

Can we inherit methods from abstract class in code behind aspx.cs file,If yes then how?

我们可以在aspx.cs文件后面的代码中继承抽象类的方法,如果是,那么如何?

1 个解决方案

#1


0  

You can try extending your class from System.Web.UI.Page class. In this way, your web pages can inherit from your class and can extend the functionality.

您可以尝试从System.Web.UI.Page类扩展您的类。通过这种方式,您的网页可以从您的类继承并可以扩展功能。

public abstract class stuff1 : Page
{
    public abstract void print();
}


public partial class _Default : stuff1
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public override void print()
    {
        throw new NotImplementedException();
    }
}

#1


0  

You can try extending your class from System.Web.UI.Page class. In this way, your web pages can inherit from your class and can extend the functionality.

您可以尝试从System.Web.UI.Page类扩展您的类。通过这种方式,您的网页可以从您的类继承并可以扩展功能。

public abstract class stuff1 : Page
{
    public abstract void print();
}


public partial class _Default : stuff1
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public override void print()
    {
        throw new NotImplementedException();
    }
}