Master Pages
Master Pages
NET
Master Pages
1
ASP.net Master Pages
The master page defines placeholders for the content, which can
be overridden by content pages.
When users request the content page, ASP.NET merges the pages to produce
output that combines the layout of the master page with the content of the
content
When users request the content page, ASP.NET merges the pages to produce
output that combines the layout of the master page with the content of the
content page.
3
4
Example web site:
5
.
6
Understanding Master Pages
• A master page always has a MASTER file extension.
• A master page is always an organization tool for other Web pagges.
• it contains a special tag that identifies it as a master page to the Web
server.
7
• a master page contains ContentPlaceHolder controls that tell someone using
the master page where to add the unique information for the Web page.
• When the server sees the MasterPageFile attribute, it reads the information
found in the associated MASTER file before it reads the content from the ASPX
page. It uses the MASTER file content to build a framework for the ASPX page
and then places the unique ASPX page content within the framework.
8
Creating the Master Page
• The easiest way to add a master page to the Web site is to open Solution
Explorer. Right-click the project entry and choose Add New Item from the
context menu.
• Select Master Page option.
• Select a language for the master page you want to create.
• Click Add to add the master page to the project.
• Master pages always must have one content area as a minimum.
9
Creating a Content Page Using a Master
Page
Adding content pages doesn’t have to be slow
or time consuming. The easiest method for
creating a content page based on master page
is to:
• open the master page.
• right-click anywhere on the form in Design
view.
• choose Add Content Page from the context
menu.
10
Another way to create a content page using a master page is to:
• right-click the project entry in Solution Explorer.
• Choose Add New Item from the context menu.
• you’ll see the Add New Item dialog box.
• Select Web Form option.
• choose a programming language.
• type a name for the file.
• Click Select Master Page option in this dialog box.
• Click Add.
11