View Single Post
  #2 (permalink)  
Old March 5th, 2009, 05:47 PM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Is this the basic Idea of it?
Not really; there are a few things wrong with your reasoning.

First of all, you can't have Master Pages inherit BasePage. BasePage (and all ASPX pages) ultimately inherit System.Web.UI.Page while a Master Page inherits
System.Web.UI.MasterPage. This means you cannot simply have the MasterPage inherit BasePage (although you could create a separate Master Page base page and inherit from that.

Secondly, a BasePage is mostly about logic, not presentation. I see a Google Analytics scripts more as presentation as it generate script that ends up in the browser. Although you could use code to create a new server control (like a Literal) and dynamically inject it in the page or head section, it doesn't feel right.

Personally, I don't mind duplicating a bit of static code like that in a few master pages. If you only want to add it once, you can always use a nested master page where the top most parent contains the Google tracking code.

YMMV of course. It's technically feasible to add this code to a BasePage, so you can always do it if you like the idea....


Imar Spaanjaars
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!