|
Page 1 of 3
ASP.NET 2.0 Training : Working With Master Pages
In this Tutorial you will learn how to work with Master Pages, create a file system on website, create a Master Page, create layout table for the Master Page, To add static content to the master page and add a content placeholder.
Creating a Simple Master Page
As pointed out in the preceding section “Working with Master Pages”, Master pages can be simple or complex. We shall start by creating a simple master page and then go on to understanding the complexities that can be interwoven.
A master page can be created using the Windows Notepad or the Microsoft Visual Web Developer which gives full designer support for building master pages.
We shall now create a simple master page titled Simple Master Page. This page will contain a HTML table with one ContentPlaceHolder control.
To create a file system Web site
1. Open Visual Studio Developer environment
2. On the File menu, click NewWeb Site.
The New Web Site dialog box appears.

3. Under Visual Studio installed templates, click ASP.NET Web Site.
4. In the Location box, enter the name of the folder where you want to keep the pages of your Web site. Here we are creating a File system folder so we do not change the contents of the combo box.
5. In the Language list, click the programming language you prefer to work in. We propose to work with C sharp. So we select that.
6. Click OK.
Visual Web Developer creates the folder and a new page named Default.aspx.

Creating the master page
1. In Solution Explorer, right-click the name of your Web site, and then click AddNew Item.

2. Under Visual Studio installed templates, click Master Page.

3. In the Name box, type MasterPage.
4. Select the Place code in separate file box.
5. In the Language box, click the programming language you prefer and then click Add.
The new master page opens in Source view.

At the top of the page, the page includes a < %@ master % > declaration instead of the < %@ page % > declaration normally found at the top of ASP.NET pages. The body of the page contains an < asp:contentplaceholder > control, which is the area of the master page where replaceable content will be merged from content pages at run time.
This master page is now the template for the pages in the web site. It can contain combinations of text and controls. It can also contain one or more ContentPlaceHolders which will determine where dynamic content will appear.
We will now position a table to help place the elements on the page. We will start by creating a layout table to hold the master elements and later we will position the ContentPlaceHolder control in an appropriate place.
|