Nishant Nishant - 1 month ago 8
ASP.NET (C#) Question

can we inherit more then on class in asp.net aspx page?

I want to inherit more than one class is there any method?

For instance in login.aspx page:

<%@ page language="c#" codefile="nishant.aspx.cs" autowireup="true" inherit="nishant"%>


now code behind file

nishant.aspx.cs:

class nishant
{
//code...
}

class bill
{
//code.....
}


Now, I want to inherit bill class then how I will ?

Answer

.NET does not support multiple inheritance, this includes asp.net, so no, this is not possible.

You can have your nishant class inherit from the bill class or the other way around, if you want to share functionality. You page can then inherit from the inheriting class and access the functionality of both.

Another option is to inherit from one class and implement an interface (or several interfaces), but the fact that you can implement more than one interface is not the same as multiple inheritance.

There are other things that can be done, depending on what exactly you are trying to achieve (I am primarily thinking about composition versus inheritance).

Comments