Webform inheritance

dominico

Well-known member
Joined
Mar 9, 2005
Messages
57
Programming Experience
3-5
Could someone please tell me how we can inherit a webform so that we can use its procedures ?

I did "Inherits form2" under the class of my mainform but it didn't take it when I do "call form2.doit(value)" function.

I also tried "Imports mywebsite.form2" but it didn't work either.

Advise please

Many thanks in advance.

Dominico
 
Last edited:
If you inherit from a class then you can call Me.DoIt() if your derived class does not also have a method called DoIt, or you can call MyBase.DoIt() whether your derived class has a similarly named method or not.
 
jmcilhinney said:
If you inherit from a class then you can call Me.DoIt() if your derived class does not also have a method called DoIt, or you can call MyBase.DoIt() whether your derived class has a similarly named method or not.


jmcilhinney, good to hear from you again my good friend. Thanks for the direction above. Another thing I don't understand is that why we cannot use both statements below in my base class ? If I add "inherits form2" below then I have to comment out the "inherits system.web.ui.page" below in order to not getting error. According to the error message, it says that "only one class can be inherited." I don't understand. What if I need to use functions from two or three webforms of the website ? How can inherit more than just one ?

' Inherits System.Web.UI.Page
Inherits form2

dominico
 
As the error message suggests, a class can only have one base class. Some languages, including Java, allow multiple inheritance. There are reasons for allowing only a single base class, but I can't remember what I've read on the subject before. You should do a bit of reading on inheritance if you're interested. Note that if Form2 inherits from System.Web.UI.Page, then Form3 can inherit from Form2 and will, as a consequence, inherit the functionality of System.Web.UI.Page as well. Also, a class can implement multiple Interfaces, so you might like to read up about them as well.
 
jmcilhinney said:
As the error message suggests, a class can only have one base class. Some languages, including Java, allow multiple inheritance. There are reasons for allowing only a single base class, but I can't remember what I've read on the subject before. You should do a bit of reading on inheritance if you're interested. Note that if Form2 inherits from System.Web.UI.Page, then Form3 can inherit from Form2 and will, as a consequence, inherit the functionality of System.Web.UI.Page as well. Also, a class can implement multiple Interfaces, so you might like to read up about them as well.


Yes jmcilhinney, it is clear to me now. Thanks for the explaination. So in order to use several webforms I would have to break up the inheritances one by one through the child forms. We simply cannot group them all on the mainform I guess. Hmmm...I thought it worked like C++'s inheritance.

I did my own research on it but MSDN Library didn't mention about why two classes above couldn't be in the same base class. I spent a lot of time doing researches when encounter previous issues. I also used Google to find answers but still no luck. The thing that wearies me down mostly is spending so much time looking for solutions. Programming is not time consuming but finding a solution is. I thank you so much for making my life easier. I spent 6 hours on this particular issue since Friday.

Thanks again buddy.

dominico
 
Back
Top