Ajay
Ajay

Reputation: 1

Using multiple contentPlaceHolders in ASP.NET masterpage

I am creating a website that has different menus in different pages. So i am creating a Master page with 3 content place holders for Page Heading, Menu and Content Respectively. I am not able to create content pages for this master page. Any help would be appreciated. Please forgive me if I have not followed the proper guidelines as I am a newbie.

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="PTS.Master.cs" Inherits="PTS.UI.Site1" %>

<!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>Patient Tracker System</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
    <style type="text/css">
        .style1
        {
            font-size: small;
        }
    </style>
</head>
<body>
<section id = "main>
 <asp:ContentPlaceHolder ID="ContentPlaceHolderMain" runat="server">
    <form id="form1" runat="server">
    <div id="wrapper">
    <div id="page">
        <div id="page-bgtop">
            <div id="page-bgbtm">
                <div id="content">
                   <!-- Enter Your Contents Here-->
                    <asp:ContentPlaceHolder ID="ContentPlaceHolderContent" runat="server">
                    </asp:ContentPlaceHolder>
                </div>
                <!-- end #content -->
                <div id="logo">
                    <h1 class="style1"><a href="#">Patient Tracker System</a></h1>
                    <br />
                    <br />
                     <asp:ContentPlaceHolder ID="ContentPlaceHolderPageHead" runat="server">
                    </asp:ContentPlaceHolder>

                </div>
                <div id="sidebar">

                    <%--Paste your Customized Menus--%> 
                    <asp:ContentPlaceHolder ID="ContentPlaceHolderMenu" runat="server">
                    </asp:ContentPlaceHolder>
                </div>
                <!-- end #sidebar -->
                <div style="clear: both;">&nbsp;</div>
            </div>
        </div>
    </div>
    <!-- end #page -->
</div>
<div id="footer">
    <p>Copyright (c) 2012 Patient Tracker System.</p>
</div>
<!-- end #footer -->
    </form>
     </asp:ContentPlaceHolder>
    </section>
</body>
</html>

Upvotes: 0

Views: 6112

Answers (1)

JohnB
JohnB

Reputation: 19012

Anything inside a ContentPlaceHolder on your Master Page is default content. What "default content" means is that if you do not specify contents for that ContentPlaceHolder on your child page, the default content will get rendered. This is useful for reducing code duplication in some situations.

However, you have your entire <form> wrapped inside ContentPlaceHolderMain, which is not a good pattern.

Your Master Page looks mostly correct, but you probably want to remove the ContentPlaceHolderMain opening and closing tags.

Then you will be left with the 3 ContentPlaceHolders that you mention in your question.

Also, you have a typo in one of your comment blocks:

<%--Paste your Customized Menus--%>

Should be this instead:

<!-- Paste your Customized Menus -->

Upvotes: 3

Related Questions