Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 30th, 2010, 12:49 PM
Authorized User
 
Join Date: Apr 2010
Posts: 18
Thanks: 7
Thanked 0 Times in 0 Posts
Default 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
 
Old May 1st, 2010, 04:15 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
flapjack (May 1st, 2010)
 
Old May 1st, 2010, 09:33 AM
Authorized User
 
Join Date: Apr 2010
Posts: 18
Thanks: 7
Thanked 0 Times in 0 Posts
Default General question - Master Pages, Base pages, templates and OOP.

Many thanks Imar. Starting to understand it now!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Base Page and Master Pages Will BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 14 January 22nd, 2010 05:04 PM
Master Pages micptpuser ASP.NET 2.0 Basics 6 January 8th, 2009 04:50 AM
Master Pages Jayahar ASP.NET 3.5 Basics 1 September 2nd, 2008 04:20 PM
Master Pages, Content Pages and CSS carliviris Visual Studio 2005 0 January 8th, 2008 05:56 PM
Master pages wunnavabk ASP.NET 2.0 Professional 1 June 25th, 2007 07:09 AM





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