p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 (http://p2p.wrox.com/forumdisplay.php?f=389)
-   -   General question - Master Pages, Base pages, templates and OOP. (http://p2p.wrox.com/showthread.php?t=79256)

flapjack April 30th, 2010 12:49 PM

General question - Master Pages, Base pages, templates and OOP.
 
Hi Imar,

I'm doing Chapter 6 and am trying to piece it all together. Do the pages which are based on the user defined template actually inherit from Master Page and Base Page. If so, is this multiple inheritance and Does C# support this. Also, does the page inherit from the Template too? I'm trying to fit this in with what I know about the OO Paradigm which I learnt many years ago at Uni using java. I know pages definitely inherit from BasePage, that much is clear, but I don't see where Master Pages and Templates fit in, unless they are part of some (under the hood) .Net Ftamework mechanism and handled differently. Sorry to be so pedantic about this but I am really puzzled.

Cheers Bill

Imar May 1st, 2010 04:15 AM

Quote:

Sorry to be so pedantic about this but I am really puzzled.
You're not pedantic, so don't worry ;-)

The template file is just that: a template. It's only purpose is to give you a few code files with ready-made code when you create a new page. It's in no way used or around anymore at run-time. Think of it as a Microsoft Word Template: it's just a starting point for new files. So, all it does is give you a new ASPX page where the code behind class inherits BasePage which takes me to your next question.

No, .NET does not support multiple inheritance (although you can implement multiple interfaces). So, a page called MyPage.aspx could have a code behind class called MyPage. This class in turn inherits BasePage which in turn inherits System.Web.UI.Page (which in turn inherits from another class). The full hierarchy is like this:

Code:

System.Object
  System.Web.UI.Control
    System.Web.UI.TemplateControl
      System.Web.UI.Page
        BasePage
          MyPage

Master Pages don't participate in the class hierarchy of a Page. Instead, they form their own hierarchy:

Code:

System.Object
  System.Web.UI.Control
    System.Web.UI.TemplateControl
      System.Web.UI.UserControl
        System.Web.UI.MasterPage

If you had the need, you could create your own BaseMasterPage class and let your custom master page inherit from that page. Since you typically only have a few master pages, I usually don't do this though.

At run-time, the Master Page and Content Page are merged to form one complete page. So, code wise they are not related (they don't inherit from each other), but feature-wise they are related of course as together the form the final presentation of the page.

Does this help?

Imar

flapjack May 1st, 2010 09:33 AM

General question - Master Pages, Base pages, templates and OOP.
 
Many thanks Imar. Starting to understand it now!


All times are GMT -4. The time now is 02:44 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.