ARTICLE

Creating Master Page (Default Content) in ASP.Net: Part 2

Posted by Abhimanyu Kumar Vatsa Articles | ASP.NET using VB.NET August 10, 2010
This is my series of articles on Master Page and in this article we will discuss how to create default content in Master Page
Reader Level:

Introduction

Here is Part 1

We do not have to associate a Content control with every ContentPlaceHolder control contained in a Master Page. We can provide default content in a ContentPlaceHolder control, and the default content will appear unless it is overridden in a particular content page. For example, the Master Page given below includes an additional column, which displays a banner advertisement. The banner advertisement is contained in a ContentPlaceHolder control named Add_of.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<
head id="Head1" runat="server">
    <style type="text/css">
        html
        {
            background-color:silver;
            font:14px Arial,Sans-Serif;
        }
        .content
        {
            margin:auto;
            width:700px;
            background-color:white;
            border:Solid 1px black;
        }
        .leftColumn
        {
            float:left;
            padding:5px;
            width:200px;
            border-right:Solid 1px black;
            height:700px;

        }
        .middleColumn
        {
            float:left;
            padding:5px;
        }
        .rightColumn
        {
            float:right;
            width:auto;
            height:auto;
            border-left:solid 1px black;
            border-bottom:solid 1px black;
            background-color:#eeeeee;
            text-align:center;
        }
        .ad
        {
            margin-top:20px;
        }
        .clear
        {
            clear:both;
        }
    </style>
    <title>Default Content in Master Page</title
>
</head>
<
body>
    <form id="form1" runat="server">
    <div class
="content">

        <div class="leftColumn">
            <asp:contentplaceholder
                id="ContentPlaceHolder1"
                runat="server"/>
        </div
>

        <div class="middleColumn">
            <asp:ContentPlaceholder
                id="ContentPlaceHolder2"
                runat="server" />
        </div
>

        <div class="rightColumn">
            <asp:ContentPlaceHolder
                id="Add_of"
                Runat="server">
                <asp:Image
                    id="imgAd"
                    ImageUrl="~/adds/CSSiteLogo.gif"
                    CssClass="ad"
                    AlternateText="Add of C# CORNER"
                    Runat="server" />
            </asp:ContentPlaceHolder>
        </div
>

        <br class="clear" />

    </div>
    </form
>
</body>
</
html>

The content page picture given below uses the Master Page. It does not include a Content control that corresponds to the Add_of control in the Master Page. When we open the page in a browser, the default banner advertisement is displayed. Remember as we have used the CSS the advertisement will automatically be placed as per the amount of texts.

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<asp:Content
    ID="LeftOne"
    ContentPlaceHolderID="ContentPlaceHolder1"
    Runat="Server">
    <b>TITLE</b>
    <br />This is my data area.
    <br />This is my data area.
    <br />This is my data area.
    <br />This is my data area.
</asp:Content>

<asp:Content
    ID="RightOne"
    ContentPlaceHolderID="ContentPlaceHolder2"
    Runat="Server">
    <b>TITLE</b>
    <br />This is my data area.
    <br />This is my data area.
    <br />This is my data area.
    <br />This is my data area.
    <br />This is my data area.
    <br />This is my data area.
    <br />This is my data area.
    <br />This is my data area.
    <br />This is my data area.
</asp:Content>

MasterPage2.gif

Note: Continue in Next Part.

HAVE A GREAT CODING!
 

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Become a Sponsor