Sie sind auf Seite 1von 7

creating consistent looking web sites

Master pages
ASP.NET master pages allow you to create a

consistent layout for the pages in your application.


A single master page defines the look and feel and
standard behavior that you want for all of the
pages (or a group of pages) in your application.
You can then create individual content pages that
contain the content you want to display. When
users request the content pages, they merge with
the master page to produce output that combines
the layout of the master page with the content
from the content page.

Master Page
An ASP.NET file with a .master file extension.
A master page contains a layout that includes

text, HTML, and server controls.


Instead of an @ Page directive, it contains
an @ Master directive.
A master page typically includes the page
structure (usually an HTML table), company
name and logo, and site navigation.
To enable pages to insert content, a master
page contains one or more
ContentPlaceHolder controls.

Content Page
A content page defines the

ContentPlaceHolder controls in a master page,


essentially filling in the blanks. A content page
is a standard .aspx file and is bound to the
master page using the MasterPageFile
attribute in the @ Page directive.
Master pages provide templates that you can
use to create consistent Web pages
throughout an application.

continued
To use master pages, first create a master

page and add layout tables and other


common elements. Then add
ContentPlaceHolder controls to the master
page. To create the content pages, add
standard Web forms, select the master page
check box when creating the page, select the
master page, and then add content to the
page.

Content page
You define the content for the master page's

placeholder controls by creating individual


content pages, which are ASP.NET pages (.aspx
files and, optionally, code-behind files) that are
bound to a specific master page. The binding is
established in the content page's @ Page
directive by including a MasterPageFile
attribute that points to the master page to be
used. For example, a content page might have
the following @ Page directive, which binds it to
the Master1.master page.
<%@ Page Language="C#"

MasterPageFile="~/MasterPages/Master1.master"
Title="Content Page"%>

Replaceable content placeholder control


These placeholder controls define regions where replaceable content will

appear.
<%@ Master Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML

1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >


<head runat="server" >
<title>Master page title</title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td><asp:contentplaceholder id="Main" runat="server" /></td>
<td><asp:contentplaceholder id="Footer" runat="server" /></td>
</tr>
</table>
</form>
</body>
</html>

Das könnte Ihnen auch gefallen