ASP.NET
  Home arrow ASP.NET arrow Page 6 - How to Use Master Pages (Conclusion)
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 (Conclusion)
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2005-12-08

    Table of Contents:
  • How to Use Master Pages (Conclusion)
  • How to add content to a page
  • How to access master page controls from a content page
  • How to access a public property of the master page from a content page
  • How to use nested master pages
  • How to create nested master pages

  • 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 (Conclusion) - How to create nested master pages


    (Page 6 of 6 )

    Unfortunately, Visual Studio 2005 doesn’t support nested master pages in Design view. Microsoft has indicated that nested master pages may be supported in design view in a future version of Visual Studio. But until then, you’ll have to work in Source view to create nested master pages and the content pages that use them. This is described in figure 3-11.

    Note that no special coding is required to create a parent master page. As a result, the MasterPage.master page that was shown earlier in this chapter will work fine as a parent master page.

    To create a child master page, first use the Add New Item command to add a new item to the web site and choose Master Page as the template for the new item. Then, in Source view, delete all the generated code except for the Master directive and the ContentPlaceHolder element. Change the ID attribute of the ContentPlaceHolder element as appropriate. In this figure, the ID of this element is set to Project.

    Next, add a MasterPageFile attribute to the Master page directive. The value of the MasterPageFile attribute should be the name of the page you want to use as the parent master page.

    Finally, add a Content element to the master page so that it contains the ContentPlaceHolder element. The ContentPlaceHolderID attribute of the Content element should name the ContentPlaceHolder element in the parent master page. In this example, the ContentPlaceHolderID attribute specifies Main as the name of the content placeholder. If you look back to figure 3-4, you’ll see that Main is the name of the content placeholder in MasterPage.master.

    Once you’ve created a child master page, you can create a content page as shown in the second code example in this figure. Here, the MasterPageFile attribute for the Page directive specifies the name of the child master page (ProjectsMaster.master). In addition, the ContentPlaceHolderID attribute of the Content element specifies Project, which matches the ID attribute of the ContentPlaceHolder element in ProjectsMaster.master.

    Frankly, the lack of Design view support for nested master pages is a major impediment to their use. So if your application requires nested master pages, be prepared to do most of your development work without the benefit of Design view.

    A child master page (ProjectsMaster.aspx) (figure 3-11)

    <%@ Master Language="VB" CodeFile="ProjectsMaster.master.vb" Inherits="ProjectsMaster" MasterPageFile="~/MasterPage.master"%>

    <asp:Content runat=server ContentPlaceHolderID=Main>
      <table border=0 cellpadding=2 cellspacing=0>
        <tr>
          <td height=40 bgcolor=gainsboro>
            <span style="font-size: 24pt">Do-It-Yourself Projects</span>
          </td>
        </tr>
        <tr>
          <td valign=top> 
            <asp:contentplaceholder id="Project" runat="server">
            </asp:contentplaceholder>
          </td>
        </tr>
      </table>
    </asp:Content>

    A content page that uses a child master (Tombstone.aspx)

    <%@ Page Language="VB" MasterPageFile="~/ProjectsMaster.master" AutoEventWireup="false" CodeFile="Tombstone.aspx.vb" Inherits="Tombstone" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="Project" Runat="server"><br /> Here's how to create your own custom tombstones to give your front-yard cemetery a spooky atmosphere!<br /><br />

    Materials needed:<br /><br />

      1. Sheet of 2" insulation foam<br />
      2. Gray latex paint<br />
      3. Stone finish spray paint<br />
      4. Epitath printed from computer<br />
      5. Tape<br /><br />

    Steps:<br /><br />

    1. Print the epitath you want to use on normal computer paper.<br />
    2. Use a Sabre Saw to cut out a piece of insulation foam the size you want your tombstone to be.<br />
    3. Tape the printed epitath to the face of the tombstone.<br />
    4. Use a rotary tool to carve the lettering. Carve right through the paper.<br />
    5. Paint the tombstone with the gray latex paint.<br />
    6. Spray the tombstone with the stone finish paint.

    </asp:Content>

    Description

    • Because the Web Forms Designer doesn’t support nested master pages, you have to work in Source view to create child masters and content pages that use a child master.
    • To create a child master page, add a MasterPageFile attribute to the Master page directive of a master page. Then, delete the rest of the generated code except for the ContentPlaceHolder element, and create a Content element that includes the ContentPlaceHolder element.
    • To create a content page that uses a child master, specify the child master in the content page’s MasterPageFile element. Then, add a Content element with the content for the page, and set the ContentPlaceHolderID attribute to the ID of the child master’s content placeholder.

    Perspective

    I hope this chapter has illustrated the power of master pages. In fact, I recommend that you use master pages for all but the simplest applications, even if you start out with nothing in your master pages but placeholders. Then, when you’re ready to provide a professional look to your content pages, you can enhance the master pages, which will also enhance all of your content pages.

    The alternative is to convert regular content pages so they use the master pages that you develop later on. But as figure 3-6 shows, that’s a time-consuming and error-prone procedure. How much better it is to think ahead.

    New terms

    master page
    content page
    content placeholder
    nested master pages
    parent master
    child master


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Murach’s ASP.NET 2.0 Upgrader’s Guide: VB...
     

    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

    - Developing a Mini ASP.NET AJAX Server Centri...
    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




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