Wednesday, July 4, 2007

Points to remember regarding Master Pages

Advantages of Master Pages
Master pages provide functionality that developers have traditionally created by copying existing code, text, and control elements repeatedly; using framesets; using include files for common elements; using ASP.NET user controls; and so on. Advantages of master pages include the following:

  1. They allow you to centralize the common functionality of your pages so that you can make updates in just one place.
  2. They make it easy to create one set of controls and code and apply the results to a set of pages. For example, you can use controls on the master page to create a menu that applies to all pages.
  3. They give you fine-grained control over the layout of the final page by allowing you to control how the placeholder controls are rendered.
  4. They provide an object model that allows you to customize the master page from individual content pages.

Run-time Behavior of Master Pages
At run time, master pages are handled in the following sequence:

  1. Users request a page by typing the URL of the content page.
  2. When the page is fetched, the @ Page directive is read. If the directive references a master page, the master page is read as well. If this is the first time the pages have been requested, both pages are compiled.
  3. The master page with the updated content is merged into the control tree of the content page.
  4. The content of individual Content controls is merged into the corresponding ContentPlaceHolder control in the master page.
  5. The resulting merged page is rendered to the browser.