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 June 20th, 2009, 12:39 PM
Registered User
 
Join Date: Jun 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Base Page vs MasterPage.vb - Ch 6

As I was reading Chapter 6 regarding creating a Base Page, I was curious as to why we can't check for a missing Page Title within the Code Behind of the Master Page ... instead of in a separate page within the App Code folder.And if that could work, could everything that would be done within a Base Page be done in th Master Page's Code Behind.

If that would work, how would it be done?

Thanks ... Jeff
 
Old June 20th, 2009, 12:58 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Jeff,

You could, but I wouldn't do it.

A Master Page is about reuse of design, while a BasePage is about reuse of logic. It's common to have more than 1 MasterPage in a project for various style related reasons, while you typically only have one BasePage you inherit from. This would mean you need to duplicate your code in multiple master pages instead of in a single base page.

Also, it doesn't feel right. Your Web Pages inherit from Page (or from the BasePage in between) that provides the Title so it makes sense to make the class itself responsible for checking its title and other actions you may add to the master page.

So, yes, you could, but I wouldn't do it.

For a similar discussion: Base Page and Master Pages

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!
 
Old June 20th, 2009, 06:36 PM
Registered User
 
Join Date: Jun 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar ... Knowing that I could but that I shouldn't is exactly what I wanted to know. Being a novice, it's gratifying to know that I figured out something that was possible. However, being a novice also means that I don't know what the Best Practices are yet. So, your answer was perfect.

Also, your book is AWESOME!!!!!
 
Old June 21st, 2009, 04:10 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:
Also, your book is AWESOME!!!!!
Thank you! Spread the word, spread the word..... ;-)

In case you still want to do it (even though you shouldn't) here's how to check the title in the Master Page:

csharp Code:
protected void Page_PreRender(object sender, EventArgs e)
{
  if (this.Page.Title == "Untitled Page" || string.IsNullOrEmpty(this.Page.Title))
  {
    throw new Exception("Page title cannot be \"Untitled Page\" or an empty string.");
  }
}

vbnet Code:
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) _
              Handles Me.PreRender
  If Me.Page.Title = "Untitled Page" Or String.IsNullOrEmpty(Me.Page.Title) Then
    Throw New Exception("Page title cannot be ""Untitled Page"" or an empty string.")
  End If
End Sub
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!





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
The base page in Appendix C has a problem thrylos97 BOOK: Beginning Spring Framework 2 ISBN: 978-0-470-10161-2 1 August 24th, 2009 04:05 AM
Using JScript on page inherited from MasterPage VictorVictor ASP.NET 2.0 Basics 13 August 11th, 2006 11:58 AM
Masterpage Question and Misprint on page 269 stanguss BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 February 24th, 2006 11:31 AM
VB.net 2K3 Ch. 5 Confusion page 150 ralphtrent BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 5 June 9th, 2004 12:30 PM





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