ASP.NET 2.0 Master Pages

|  | Search W3Schools : |

HOME | HTML | CSS | XML | JAVASCRIPT | ASP | PHP | SQL | MORE... |  | References | Examples | Forum | About

ADVERTISEMENTS XML Certification Download XML editor Custom Programming |  |

Table of contents

ASP.NET Tutorial
.NET HOME
.NET Intro
.NET vs ASP
.NET Install
.NET Pages
.NET Controls
.NET Events
ASP.NET Forms
.NET Forms
.NET ViewState
asp:TextBox
asp:Button
ASP.NET Binding
Data Binding
ArrayList
Hashtable
SortedList
XML Files
asp:Repeater
asp:DataList
ASP.NET Database
.NET DB Connection
ASP.NET 2.0
2.0 New Features
2.0 Master Pages
2.0 Navigation
References
HTML Controls
Web Controls
Validation Controls
Examples
ASP.NET Examples

Selected Reading

Web Statistics
Web Glossary
Web Hosting
Web Quality
W3Schools Tutorials
W3Schools Forum
Helping W3Schools

# ASP.NET 2.0 - Master Pages

Master pages provide templates for other pages on your web site.

## Master Pages

Master pages allow you to create a consistent look and behavior for all the pages (or group of pages) in your web application.

A master page provides a template for other pages, with shared layout and functionality. The master page defines placeholders for the content, which can be overridden by content pages. The output result is a combination of the master page and the content page.

The content pages contains the content you want to display.

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.

## Master Page Example:

    <%@ Master %>

    <html>
    <body>
    <h1>Standard Header For All Pages</h1>

    <asp:ContentPlaceHolder id="CPH1" runat="server">
    </asp:ContentPlaceHolder>

    </body>
    </html>

The master page above is a normal HTML page designed as a template for other pages.

The @ Master directive defines it as a master page.

The master page contains a placeholder tag <asp:ContentPlaceHolder> for individual content.

The id="CPH1" attribute identifies the placeholder, allowing many placeholders in the same master page.

This master page was saved with the name "master1.master"

Note: The master page can also contain code, allowing dynamic content.

## Content Page Example:

    <%@ Page MasterPageFile="master1.master" %>

    <asp:Content
    ContentPlaceHolderId="CPH1" runat="server">

    <h2>Individual Content</h2>
    <p>Paragrap 1</p>
    <p>Paragrap 2</p>

    </asp:Content>

The content page above is one of the individual content pages of the web.

The @ Page directive defines it as a standard content page.

The content page contains a content tag <asp:Content> with a reference to the master page (ContentPlaceHolderId="CPH1").

This content page was saved with the name "mypage1.aspx"

When the user requests this page, ASP.NET merges the content page with the master page.

Click to display mypage1.aspx.

Note: The content text must be inside the <asp:Content> tag. No content is allowed outside the tag.

## Content Page With Controls:

    <%@ Page MasterPageFile="master1.master" %>

    &br<asp:Content
    ContentPlaceHolderId="CPH1" runat="server">

    <h2>W3Schools</h2>
    <form runat="server">
    <asp:TextBox id="textbox1" runat="server" />
    <asp:Button id="button1" runat="server" text="Button" />
    </form>

    </asp:Content>

The content page above demonstrates how .NET controls can be inserted into the content page just like an into an ordinary page.

Click to display mypage2.aspx.

Ektron CMS400.NET Version 7.6 delivers all of the flexibility and features you need to deploy the Web site you want, quickly and efficiently. learn more...

6 ways to take your site to the next level with Ektron:

| Create site stickiness through social networking. Keep it personal, relevant and interactive and they'll come back for more.
| Keep it open. Your site needs to be ready and able to connect to outside services. Ektron's open API gives you maximum flexibility.
| Streamline content and document management. Users need to quickly and intuitively find and add information.
| Empower your content authors. Reduce IT bottlenecks by allowing business users to create and edit Web content and forms.
| Climb to the top of search rankings. SEO tools, URL aliasing and eCommerce for your digital marketing strategy
| Add powerful Web 2.0 tools like blogs, wikis, forums, geo-mapping, rating systems and RSS feeds easily.

See why there are 20,000+ Ektron integrations worldwide. Request an INSTANT DEMO or download a FREE TRIAL today.

WEB HOSTING
Password Protect Your Web Pages
$15 Domain Name Registration Save $20 / year!
Buy UK Domain Names Register Domain Names
Cheap Domain Names Cheap Web Hosting
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Web Hosting
FREE Web Hosting

WEB BUILDING
Website Templates Flash Templates Website Builder Internet Business Opportunity
Custom Programming
FREE Trial or Demo Web Content Manager Forms,Web Alerts,RSS
Download XML editor
FREE Flash Website
FREE Web Templates

EDUCATION
US Web Design Schools
HTML Certification
JavaScript Certification
XML Certification
PHP Certification
ASP Certification

HOME or Top of Page |  | Printer Friendly
W3Schools is for training only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy. Copyright 1999-2009 by Refsnes Data. All Rights Reserved.