ASP.NET
  Home arrow ASP.NET arrow Page 3 - How to Use Master Pages
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

How to Use Master Pages
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 22
    2005-12-01

    Table of Contents:
  • How to Use Master Pages
  • How to create a master page
  • The aspx code for a new master page
  • The aspx code for the Halloween Store master page
  • The code-behind file for the master page

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    How to Use Master Pages - The aspx code for a new master page


    (Page 3 of 5 )

    The listing at the top of figure 3-3 shows the aspx code that’s generated when you create a master page using the Master Page template. As you can see, this code is similar to the aspx code generated for a regular ASP.NET web page, with two important differences.

    First, instead of a Page directive, the code begins with a Master directive. This indicates that the file contains a master page rather than a regular ASP.NET page. Second, the Div element that normally contains the content for the page now contains a ContentPlaceHolder control.

    Notice that the master page file is itself a well-formed HTML document with html, head, and body elements. The body element includes a form element, which in turn contains the ContentPlaceHolder control. Any elements you add to the master page should appear within the form element, but outside of the ContentPlaceHolder control.

    The aspx code for a new master page (figure 3-3) 

    <%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>

    <!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>Untitled Page</title>
    </head>
    <body>
      </form id="form1" runat="server"> 
      <div>
        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
        </asp:contentplaceholder>
      </div>
      </form>
    </body>
    </html>

    Attributes of the Master page directive

    Attribute Description
    Language Specifies the language used for any code required by the page.
    CodeFile Specifies the name of the code-behind file.
    Inherits Specifies the name of the page class defined in the code-behind file.

    Attributes of the ContentPlaceHolder control 

    Attribute

    Description

    ID

    Specifies the name of the content placeholder.

    Runat

    Specifies that the control is a server-side control.

    Description

    • A master page must begin with a Master page directive and should include at least one ContentPlaceHolder control.
    • Any HTML or aspx elements that you add to the master page will be displayed on every page that uses the master page along with the ContentPlaceHolder control.

    More ASP.NET Articles
    More By Murach Publishing


       · This article is an excerpt from the book "Murach’s ASP.NET 2.0 Upgrader’s Guide: VB...
       · I would love to read the article if the sample images weren't dead links. I'm not...
       · Hi,I like the article on Master pages. I want to ask one question whether I can...
     

    Buy this book now. This article is excerpted from chapter three of the book Murach’s ASP.NET 2.0 Upgrader’s Guide: VB Edition, written by Anne Boehm and Joel Murach (Murach, 2005; ISBN: 1-890774-36-7). Check it out today at your favorite bookstore. Buy this book now.

    ASP.NET ARTICLES

    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...
    - Building an In-Text Advertising System Under...
    - Developing a Mini ASP.NET AJAX Server Centri...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT