Programming Microsoft ASP.NET 4 - Dino Esposito [169]
In the next chapter, we’ll take page authoring to the next level by exploring master pages and wizards.
Chapter 8. Page Composition and Usability
There is nothing like dream to create the future.
—Victor Hugo
It was only in the very early days of the Web that a Web site could be assembled by simply grouping distinct pages under the same host. Today, it is necessary for all pages in a Web site to define a common structure and share a common set of interface elements such as header, footer, navigation bar, ad rotators, and search and login box.
Beyond having a similar-looking and consistent layout, Web pages in a site must be easy to retrieve, understand, and navigate for users. In one word, Web pages must be enjoyable by their target audience. Most Web sites exist for strong business reasons; failing on the composition or usability aspects of site planning and development is a mistake that can cost your company much more than you might expect.
The challenge for a Web development platform is providing a technology that makes composing rich and usable pages effective in the first place, but also quick and at least relatively easy. This chapter is split into two parts, each providing a sort of checklist for the two aspects I’ve emphasized so far: composition and usability.
In the composition section, I’ll discuss master pages, cascading style sheets (CSS), and ASP.NET themes. In the usability section, I’ll touch on cross-browser rendering, site navigation, and search-engine optimization.
Page Composition Checklist
A successful Web site results from the combined effect of well-organized content and HTML appeal. You can’t do without a strong visual idea of the site that contributes to spreading the brand and making the site recognizable and, in some way, giving the site its own character. Elaborating on a successful visual idea for a site is (fortunately?) beyond the reach of most developers and definitely is a different job that requires a different set of skills.
Some point of contact between the design and development teams, however, has to be found. When the underlying platform is going to be ASP.NET Web Forms, this point of contact comes in the form of a master page template and one or more cascading style sheets. Sometimes, the style of the site is represented through one or more ASP.NET themes. A theme is a superset of a CSS and includes multiple cascading style sheets plus additional files.
Let’s begin our exploration of site composition with an in-depth look at master pages.
Working with Master Pages
In ASP.NET, master pages provide the ability to define a common layout and have it reused and shared across as many pages as you want throughout the site. Master pages improve the maintainability of the site while reducing code duplication. ASP.NET master pages basically benefits from the ASP.NET framework’s ability to merge a super-template with user-defined content replacements.
A master page is a distinct file referenced at the application level, as well as at the page level, that contains the static layout of the page. The page layout consists of regions that each “derived” page can customize. Such regions are referenced in the master page with a special placeholder control. A derived page, also known as a content page, is simply a collection of blocks the run time will use to fill the regions in the master.
The contents of a master page are merged into the content page, and they dynamically produce a new page class that is served to the user upon request. The merge process takes place at compile time and only once.
It might seem that the idea of master and content pages revolves around some sort of visual inheritance such as the form inheritance feature you might experience in Windows Forms. Abstractly speaking, the content page really looks like an inherited