ASP.NET
  Home arrow ASP.NET arrow Page 2 - Master Pages in ASP.Net 2.0
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

Master Pages in ASP.Net 2.0
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 15
    2005-09-15

    Table of Contents:
  • Master Pages in ASP.Net 2.0
  • Master Pages – The Concept
  • Content Pages
  • Going Beyond the Basics

  • 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


    Master Pages in ASP.Net 2.0 - Master Pages – The Concept


    (Page 2 of 4 )

    A Master Page is more or less just a template, or a shell. In the Master Page, you will define the look and feel across your application, as well as the common controls and functionality that is needed (a date, a login indicator, and so forth). It is possible to define multiple master pages within one site/application. For example, you could have one template for your public website, and a completely separate template for the administrative content management system in the backend. You could even have a Master Page nested within another Master Page, but now that’s just crazy!

    A "content" page is the actual page within the site that you’ll be working on, and it will inherit its UI from the Master Page. When the URL of the content page is called, ASP.Net merges the two in the background, and sends the results to the client, who of course will be completely unaware of the fancy process that just took place.

    Master Pages – The Code

    Working with Master Pages will offer a seriously difficult learning curve, as we have an outrageously high number of lines of code to learn and remember. In fact, we are tasked to learn all of two new lines of code.

    1. the first, a new directive, is this:<%@ Master %>
    2. the second, equally as daunting, is this:<asp:contentplaceholder />

    Whew, that was tough! Maybe Microsoft should rethink and create a less complex system…

    Okay, enough sarcasm. It’s actually that easy. In fact, here is all the code necessary to get a barebones Master Page up and running:

    <%@ Master %>
    <html>
    <head>
        <link rel=”Stylesheet” href=”styles.css” />
    </head>
    <body>
          <img src=”logo.gif” />
          <form runat=”server”>
                <asp:contentplaceholder runat=”server”
    id=”bodyContents”>
                      <p>default, replaceable content here</p>
                </asp:contentplaceholder>
          </form>
    </body>
    </html>

    Then you simply save this file with a .master extension, and you’re ready to go! For our example we’ll leave it as the default ‘site.master’.

    Worthy to note is that a Master Page in essence is simply an extended UserControl, so you have all of the same attributes available to the @Master directive as you would with the @Control directive.

    More ASP.NET Articles
    More By Justin Cook


       · Hi Everyone,just a quick note from the author here: hope you enjoy the article,...
     

    ASP.NET ARTICLES

    - 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
    - Building a Simple Storefront with LINQ





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