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 December 24th, 2008, 02:01 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 119
Thanks: 26
Thanked 0 Times in 0 Posts
Default BasePage & MasterPage

Hi Imar:

I just got back to reviewing what I've done so far. I finished chapter 6 couple of days ago.

I'm a little confused about one thing. I see in Solution Explorer that I have a BasePage.cs under app_code and a MasterPage.master with a MasterPage.master.cs page.

What is the difference between having a BasePage and a MasterPage? Do you always want to have both?

Rachel

P.S.

Merry Christmas!

Last edited by Rachel; December 24th, 2008 at 02:29 PM..
 
Old December 25th, 2008, 07:06 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Rachel,

While it's not the complete picture, you can see a BasePage as a way to express common behavior and a Master Page as a way to express common look and feel.

Let's take a look at how a page normally works before you use a BasePage. Each of your pages in your web site inherits from System.Web.UI.Page. This gives each page the behavior defined in this class, and gives you access to stuff like the Title, Request, Response and much more. The Page class itself inherits from another class (TemplateControl) which in turn inherits from Control which inherits Object. The full hierarchy looks like this:

Code:
 
System..::.Object
  System.Web.UI..::.Control
    System.Web.UI..::.TemplateControl
      System.Web.UI..::.Page
        YourPage
Now, with a BasePage, things change a bit. Rather than inheriting from System.Web.UI.Page, your page now inherits your BasePage that in turn inherits Page:

Code:
 
System..::.Object
  System.Web.UI..::.Control
    System.Web.UI..::.TemplateControl
      System.Web.UI..::.Page
        BasePage
          YourPage
This way, your ASPX now contains all the behavior that is defined in BasePage. The total behavior of BasePage is a combination of everything that is defined in System.Web.UI.Page (where it inherits from) plus everything that BasePage itself defines. For example, in the TIO on page 206 you'll learn how to add behavior that checks whether your ASPX page has a valid title. Your pages that inherit from BasePage now automatically get this behavior for free; all they need to do is inherit from BasePage (which you can state in the Code Behind of each ASPX page) and then the title is checked automatically at run-time.

Master Pages on the other hand define look and feel. As you learned in the beginning of chapter 6, a Master Page allows you to define regions that you need on every page in your site (at least, on the pages that use a specific Master Page). It allows you to define repeating areas like menus, footers, headers, banner areas and so on. Each page that is based on this Master Page automatically gets these regions; all it needs to do is express that it uses a Master Page (using the MasterPageFile attribute) and then fill in one or more of the ContentPlaceHolder controls that the Master Pages defines (using <asp:Content /> blocks).

Once you make a layout change to the Master Page (like adding a menu), all pages based on this Master Page automatically pick up that change.

You don't have to use a Master Page and you don't have to use a BasePage. Additionally, you can have only one of them, or both at the same time. Since they are for a large part offering non-overlapping functionality, it's perfectly OK to have an ASPX page that inherits from BasePage and that is based on another Master Page.

I usually always create my intermediate BasePage on any new web site, even if I don't have specific behavior for it. Once every page is inheriting from this BasePage, it's really easy to add behavior later. For example, if you decide you want to set some meta tags like Keywords or Description on every page, you could do this in the BasePage and all pages in your site would automatically pick up the behavior.


Hope this clarifies things a bit. If not, please let me know.

You have a Merry Christmas too!

Cheers,

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:
Rachel (December 25th, 2008)
 
Old December 25th, 2008, 11:23 AM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 119
Thanks: 26
Thanked 0 Times in 0 Posts
Default

Thank you.

That did clear it up better for me. I know you explained it in the book, but there is so much information that hearing about just these two comparisons alone, helped make it gel a little better for me.

Rachel





Similar Threads
Thread Thread Starter Forum Replies Last Post
BasePage Code for VB (Chapter 6) justinjones06 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 September 15th, 2008 01:50 AM
BasePage and Namespace Issue Eric S. Smith BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 May 28th, 2008 08:43 AM
BasePage>>TypeInitialization exception nabeelalkaff BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 November 13th, 2007 11:30 AM
Linux & KDE & C++ & QT & MYSQL & Kdevelop Munnnki Linux 0 January 2nd, 2005 05:41 PM





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