Skip to Content
Beginning ASP.NET 3.5: In C# and VB
book

Beginning ASP.NET 3.5: In C# and VB

by Imar Spaanjaars
March 2008
Intermediate to advanced content levelIntermediate to advanced
766 pages
21h 15m
English
Wrox
Content preview from Beginning ASP.NET 3.5: In C# and VB

6.2. Using a Centralized Base Page

Chapter 5 states that by default all ASPX pages derive from a class called System.Web.UI.Page. This means all of your pages have at least the behavior defined in this class.

However, there are circumstances where this behavior is not enough and you need to add your own stuff to the mix. For example, you may have the need to add behavior that applies to all the pages in your site. Instead of adding this behavior to each and every individual page, you can create a common base page. All the pages in your site can then inherit from this intermediate page instead of from the standard Page class. The left half of Figure 6-7 shows how a default ASPX page called MyWebPage inherits from the Page class directly. The right half shows a situation where the ASPX page inherits from a class called BasePage, which in turn inherits from Page.

Figure 6-7. Figure 6-7

To be able to have your pages inherit from this base page, you need to do two things:

  • Create a class that inherits from System.Web.UI.Page in the App_Code folder of your web site.

  • Make the web pages in your site inherit from this base page instead of the standard Page class.

In the following exercise you create a new base page class inside the App_Code folder. For now, the sole purpose of this class is to check the Title of the page at runtime to avoid pages with the default name of Untitled Page that ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning ASP.NET 4: in C# and VB

Beginning ASP.NET 4: in C# and VB

Imar Spaanjaars
Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Bill Evjen, Scott Hanselman, Devin Rader

Publisher Resources

ISBN: 9780470187593Purchase book