Link to home
Start Free TrialLog in
Avatar of Ben Santiardo
Ben SantiardoFlag for United States of America

asked on

Can you nherit methods from a MasterPage?

I created a MasterPage in ASP.Net 2.0 where I used the Load() event/method along with some custom methods.  I thought that when I created a new regular page and set up the MasterPageFile attribute, that the page was supposed to inherit everything from the MasterPage.  Yet I can't access any of my custom methods. I tried going into the Partial Class behind the page, and change it's inheritance from System.Web.UI.Page to the MasterPage class...but then I get an error on my Load() event/method stating it needs to be overrided.  Problem is, that if I override the method, then it losses the functionality of the original Load() method on the MasterPage...  Is there any way to inherit completely from the MasterPage? (...like the way you inherit in WinForms?)

Or am I approaching this from the wrong direction...please help!

Thanks.
Avatar of tetorvik
tetorvik
Flag of Finland image

As far as I know you cannot, however there is a workaround:

Create an interface let's say IMaster where you define methods you need.
Then make your masterpage to implement the IMaster interface.
Then on aspx page you can use ((IMaster)page.Master).CallSomeMethodDefinedInInterface();
ASKER CERTIFIED SOLUTION
Avatar of sunithnair
sunithnair

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ben Santiardo

ASKER

Creating a BasePage class that I manually inherit on all my pages worked perfectly.  Thanks...