.NET
  Home arrow .NET arrow Page 5 - Building an ASP.NET 2.0 Master Page in Thr...
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 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
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? 
.NET

Building an ASP.NET 2.0 Master Page in Three Steps
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 27
    2006-11-20

    Table of Contents:
  • Building an ASP.NET 2.0 Master Page in Three Steps
  • Step 1: Adding a Master.master page to your site
  • Step 2: Adding some features to the Master
  • Step 3: Create a web page which uses the Master
  • Adding an asp:content/ control to the 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


    Building an ASP.NET 2.0 Master Page in Three Steps - Adding an asp:content/ control to the page


    (Page 5 of 5 )

    Onto the VbDotNet.aspx page insert a tag as shown inside the <Form/> tags as shown. It immediately points to the <asp: Content/> control in the drop-down menu that is spawned.

    Make use of the drop-down pick list to configure the attributes of this control as shown. It has an ID which is just "ID="content1" as well as other attributes shown in the drop-down. One of the important items you must configure is the ContentPlaceHolderID.

    The ContentPlaceHolderID

    With the ContentPlaceHolderID being properly referred to the ContentPlaceHolderID in the Master Page, you can plug in whatever content you wish to place in the VbDotNet.aspx page. Another attribute that must be added is the runat="server" as this is a server control. Make sure you have all the values of the attributes under double quotes.

    For this tutorial only some links are added inside the <asp:content/> tags as shown with a heading inside the <h3/> tags as shown here and a <ul/> list showing some links. This is the source code of this completed page.

    <%@ Page Language="VB" 
    AutoEventWireup="false" 
    CodeFile="VbDotNet.aspx.vb" 
    Inherits="VbDotNet" 
    MasterPageFile="~/Tutorial.master"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>VISUALBASIC.NET</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <b><asp:Content ID="content1" 
    ContentPlaceHolderID="ContentPlaceHolder1" 
    runat="server"></b> <h3 style="color:Maroon">
    Welcome to the Visual Basic .NET Tutorials</h3> <ul> <li><a href="/c/a/VB.NET/Exploring-the-Dialogs-Controls-in-Vb-Net/"> Exploring the Dialogs Controls in Vb.Net </a></li> <li><a href="http://www.codeproject.com/vb/net/Migration.asp"> On Migrating a VB Project to VB.NET</a></li> <li><a href="/c/a/VB.NET/Creating-a-VBNET-Client-for-a-ColdFusion-
    Web-Service/"> VB.NET Client for a ColdFusion Web Service</a> </li> </ul>
    </asp:Content> </div> </form> </body> </html>

    The design view of this page is as shown in the next picture. The content that is coming from the Master has been grayed out as shown. Whatever is colored blue in the above source code is displayed.

    The ContentPlaceHolder page cannot have the name space and other markup tags. If you were to browse the page as is, you will get run time server errors since the ContentPlaceHolder page, which is in this case the VbDotNet.aspx, cannot have other markups. It should have <asp:Content/> as the topmost control. The cleaned-up source code for the VbDotNet.aspx page should be as shown, with no markups and no namespace reference.

    <%@ Page Language="VB"
    AutoEventWireup="false"
    CodeFile="VbDotNet.aspx.vb"
    Inherits="VbDotNet"
    MasterPageFile="~/Tutorial.master"%> <asp:Content ID="content1" 
    ContentPlaceHolderID="ContentPlaceHolder1"
    runat="server"> <h3 style="color:Maroon">Welcome to the Visual Basic 
    .NET Tutorials</h3> <ul> <li><a href="/c/a/VB.NET/Exploring-the-Dialogs-Controls-in-Vb-Net/"> Exploring the Dialogs Controls in Vb.Net </a></li> <li><a href="http://www.codeproject.com/vb/net/Migration.asp"> On Migrating a VB Project to VB.NET</a></li> <li><a href="/c/a/VB.NET/Creating-a-VBNET-Client-for-a-ColdFusion-
    Web-Service/"> VB.NET Client for a ColdFusion Web Service</a> </li> </ul>
    </asp:Content>

    When you view this in the browser, you will see the following displayed, the top and bottom coming from the Master and the content in the middle from the VbDotNet page's content.

    Adding another web page (ContentPlaceHolder)

    Every other web page at this site using the Master will be a ContentPlaceHolder page. This next page, DTS.aspx was designed very rapidly following the same procedure indicated above. An image was added to the Master Page so that every page will have the logo. This displays as shown here. Compared to using Usercontrols in VS2003 this process is very rapid.

    Here is the source of the Master that produced the above content. Some changes were made to the original Tutorial.master file. An image folder was created in the web site and an image was brought into the folder from the computer. An image control was added to the page and its URL was set to reference the image folder (shown in blue).

    <%@ Master Language="VB" 
    CodeFile="Tutorial.master.vb" 
    Inherits="Tutorial" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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:Image ID="Image1" runat="server" 
    ImageUrl="~/images/Htek.jpg" />
    <span style="color: #3300ff">
    <span style="font-size: 32pt">
    Welcome to Tutorials Haven<br />
    <br />
    </span></span> <asp:contentplaceholder 
    id="ContentPlaceHolder1" 
    runat="server">
    </asp:contentplaceholder> </div> <h4>Copy Right©Jay 2006</h4>
    </form> </body> </html>

    This next picture shows the web site directory showing all the relevant pages used in this tutorial.

    Summary

    Using the Master Page technique to get a common look and feel for the web pages on a website can be easily and rapidly implemented with the VS 2005 IDE. It is vastly superior to earlier procedures used to obtain the same effect. Although a bare bones Master was used, it is possible to provide a rich user experience by using the various other objects from the vast toolbox repository and other objects.


    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.

       · User experience is one of the most important aspects of web design. The look and...
       · Very nice, easy to understand .NET article.I remember my co-worker advocating...
       · Things are evolving and a open revolution is taking place in the Open Source area....
     

    .NET ARTICLES

    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries
    - Introducing LINQ to SQL Designer using Visua...
    - Beginning LINQ to SQL Using Visual Studio 20...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway