CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

jobs.internet.com

internet.commerce
Partners & Affiliates
Logo Design
Memory
Shop
Online Shopping
Auto Insurance Quote
Laptop Batteries
Condos For Sale
GPS Devices
Cell Phones
Career Education
Find Software
Best Price
Desktop Computers
Promos and Premiums


RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

Home >> .NET / C# >> .NET >> General ASP.NET >> Web Forms

Project Management Guide: Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.

An In-Depth Coverage of ASP.NET 2.0's Master Pages: Part 1 of 3
Rating:

Manoj Agarwal (view profile)
December 30, 2005

Environment:  ASP.NET 2.0

Go to page: Prev  1  2  

Content Pages

Once you have moved the common UI elements and code to the master page, only the page specific part will remain in the ASPX pages. This page-specific content is placed within the content control. In an ASPX page that has a master page, no content can be outside the content control; otherwise, ASP.NET would not know how to merge this page with the master page. For the ASPX page, you specify which master page to use in the page's @ Page directive by including a MasterPageFile attribute that points to the master page to be used. The content pages for your Home and About Us pages are:

Home.aspx

<%@ Page MasterPageFile="~/SiteMaster.master"
    CodeFile="Home.aspx.cs"
    Inherits="Home"
    Title="Home Page" %>
<asp:Content ID="Content1"
     ContentPlaceHolderID="myHolder"
     runat="Server">
   Welcome to Falconsoft Systems - a company formed by people
   having worked in the industry for a good many years. <p />
</asp:Content>

AboutUs.aspx

<%@ Page MasterPageFile="~/SiteMaster.master"
         CodeFile="AboutUs.aspx.cs"
         Inherits="AboutUs"
         Title="About Us Page" %>
<asp:Content ID="Content1"
     ContentPlaceHolderID="myHolder"
     Runat="Server">
   About Us - A group of IT professionals who shared a common
   vision and outlook to software design and development came
   together to form this company. <p />
</asp:Content>

AboutUs.aspx.cs

using System;
using System.Web;

public partial class AboutUs : System.Web.UI.Page
{
}

Default Content


(continued)



Web Devs:
Moonlight as a Game Developer and Win Cool Prizes by Accepting the RIA Run Challenge

Now, your mission--should you choose to accept: Take your shot at gaming stardom if you think you might have what it takes to build a cool RIA game and you could win an Xbox 360 or other fabulous prizes. Hurry! You only have until May 15, 2008 to enter. »

 
Article:
Leveraging Your Flash Development with Silverlight

You're not giving up Flash any time soon (and we don't blame you.) But if you could get your Flash application working in Silverlight, why wouldn't you? We show you the tools and techniques required to have your rockin' Flash application rolled for Silverlight. Learn more here. »

 
Article:
What Does it Take to Build the Best RIA?

With the proliferation of Rich Interactive Application (RIA) platform choices out there, you no longer have to take a one-size-fits-all approach to developing your next RIA application. Knowing the strengths (and weaknesses) of each platform can help you to decide the best RIA for your next application. »

 

Along with layout and code that applies to all pages, the master page can also supply default content, which can be overridden by content pages or displayed if not overridden. This is achieved by simply inserting the content within the ContentPlaceHolder element. For example, your MySite.master page could have the following default content:

<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
   <h2>Welcome</h2>
   Welcome to my site, where you'll find lots of interesting stuff.
</asp:ContentPlaceHolder>

Creating Master Pages through Visual Studio

In Visual Studio 2005, the way one creates an ASP.NET application has been changed a little. It can be created from File->New->Web Site. Another change made is that it's not mandatory to have IIS on the ASP.NET development machine because Visual Studio installs an ASP.NET Development Server in which the application can run.

After creating a new Web site, one can add a master page from Website->Add New Item. The Add New Item screen is shown below:


(
Full Size Image)

Figure 4: The Add New Item screen to add a master page to the Web project

After the master page has been added, you can add a Web form that uses the master page. To do this, check the Select master page option in the Add New Item screen, as shown below:


(Full Size Image)

Figure 5: Check the Select master page option to add a Web form that uses a master page

Runtime Behavior of Master Pages

The client never requests the master page directly and the master page is not known to the client. The client requests the content page (ASPX pages); if there is a master page associated with it, the master page is merged into the content page and treated as a control in the content page. ASP.NET processes a page request in the following sequence:

  1. ASP.NET fetches the page.
  2. ASP.NET determines whether the content page references a master page.
  3. If so, ASP.NET fetches the master page associated with the content page.
  4. ASP.NET merges the master page into the content page and treats it as a control in the content page.
  5. ASP.NET renders results to the browser.

Some Useful Links

1. This book has a great chapter on master pages. (You can download master page chapter for free!)
A First Look at ASP.NET v 2.0

2. The master pages section on ASP.NET Web:
Visual Web Developer 2005 Express Edition Guided Tour

About the Author
Manoj Agarwal has over a decade of industry experience on a wide spectrum of technologies. He currently runs a software company called Falconsoft Systems which specializes in consulting, application development and training mainly in Microsoft .NET. Manoj was among the top-10 winners at the nationwide Microsoft Technology Adopter Challenge.

Go to page: Prev  1  2  

Downloads

  • MasterPage_SimpleSample.zip - Sample website which uses master pages

    Tools:
    Add www.codeguru.com to your favorites
    Add www.codeguru.com to your browser search box
    IE 7 | Firefox 2.0 | Firefox 1.5.x
    Receive news via our XML/RSS feed

    Work With InterSystems. Not Separate Systems. Rapidly develop and deploy connectable applications.
    Is it time to make your move to the multi-threaded and parallel processing world? Find out!
    Data Sheet: IBM Information Server Blade
    Five Trends for Application Development. Download Your Complimentary Report. Exclusive. Act Now.
    Developing Intelligent Communications? Visit the Avaya DevConnect Center on DevX.


  • RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

    (You must be signed in to rank an article. Not a member? Click here to register)

    Latest Comments:
    No Comments Posted.
    Add a Comment:
    Title:
    Comment:
    Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



    (You must be signed in to comment on an article. Not a member? Click here to register)


    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES