Master Pages

Master pages give your site a steady look and feel
Master pages contain both HTML and a code part
They create a common template that can be used on many pages
Updating the master page automatically updates all pages using it
A master page has 2 parts
- Content that appears on each page that inherits the master page
- Regions that can be customized by the pages inheriting the master page
Master pages can contain HTML, Web controls and server side source code
- Open Visual Studio
- Add a new item
- Select Master Page

Master pages end with .Master
BY default visual studio names the master page masterPage.master
A Master page need to specify both the parts common to all pages and the parts that are customizable
Items you add to the master page appear on all pages that inherit it
Use contentPlaceHolder controls to specify a region that can be customized
Add a table to the Master page

It adds on ContentPlaceHolder by default
If you place controls outside the content placeholders they will be displayed on all pages

You can have multiple contentPlaceHolder controls
Each contentPlaceHolder control can be used to customize the ASP.Net page that inherits the master page
- Add a new item
- Select Web form
- Check Select Master Page checkbox

- Select the master page you created.
All masterpages in your site will appear

All is grayed out except the contentPlaceHolder control

You can only add controls to and modify inside the ContentPlaceHolder

The purpose of a master page is to define a template for the website

Master pages contain a default contentPlaceHolder control when you create then
To add another contentPlaceHolder control
- Open the master page
- Drag a contentPlaceHolder to the master page
This control appears in the toolbox when you are in a master page


Master pages start with <%@ Master %> directive instead of a <%@Page %> directive

Websites can have more than one master page

Using a table for layout
Select from MENU: Layout Insert Table
|
- Select the table settings
- Pick the number of rows and columns, alignment, width, height etc
- Select Header,Footer, and Side setting from the template

- Drag the contentPlaceHolder into one of the table cells

Format a table Cell
- Click inside a table cell
- Click on the style property
This opens the style builder
- Set the font, background, layout etc


Default Content in a Master page
You can put content in the contentPlaceHolder control in a Masterpage, then in the ASP.Net page you can replace it with different content or leave it in there

In the master page

In the ASP.Net page inheriting from the Master page
If it doesn’t show up in the ASP.Net page right click on the control and select Create Custom Content

You can replace this content or use the default version
You can right click the control and select Default to Master’s content

