You must Sign In to post a response.
  • Category: ASP.NET

    Implementation of Master Page

    i want to create a master page and content page. (example code)
  • #767452
    1. Create the master page. It is looks like normal page. In spite of "Page" It will be "Master". In which part of the page content will change. In that page use the "ContentPlaceHolder" and give proper name for that. You can implement scripts,styles etc as usual.
    Use the following code

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs"
    Inherits="MasterPage" %>
    < !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 id="Head1" runat="server" >
    < title>FDC DBS< /title >
    < script language="javascript" type="text/javascript" >
    < /script >
    < style type="text/css" >
    < /style >
    < /head >
    < body >
    < form id="form1" runat="server" >
    < asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" >

    < /asp:ContentPlaceHolder >
    < /form >
    < /body >
    < /html >

    2. Create Content page
    It will not have any html,header,body etc.. Because everything in the master page. Only thing is you have to specify the master page "MasterPageFile" . And you can write you html content inside the "asp:Content" tag.

    <%@ Page Language="C#" AutoEventWireup="true" Title="Page Title" CodeFile="Home.aspx.cs"
    MasterPageFile="~/MasterPage.master" Inherits="Home" %>
    < asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server" ID="phheader" >
    Place you home page content
    < /asp:Content >

    By Nathan
    Direction is important than speed

  • #767453
    not working

  • #767456
    hey krishna

    A master page is an ASP.NET file with the extension .master (for example, MySite.master) with a predefined layout that can include static text, HTML elements, and server controls. The master page is identified by a special @ Master directive that replaces the @ Page directive that is used for ordinary .aspx pages.


    kindly check the following link which wil help you

    http://www.codeproject.com/Articles/333650/Beginner-s-Tutorial-on-Master-Pages-in-ASP-NET

    very easy explanation

    hope it help you


    Regards ,
    Abhijit Patil

  • #767458
    What error you are getting?
    can you correct/remove the spaces like "< ". The code which I post is only for reference. If you create master page / content page code will populate automatically. Try that still you are facing issue let me know.

    By Nathan
    Direction is important than speed

  • #767467
    Master Page :
    name MasterPage.master

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="CategoryMaster.master.cs" Inherits="BookCategory_CategoryMaster" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>

    Add Your Required Header Here


    <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

    </asp:ContentPlaceHolder>


    Add Your Footer Here


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

    ContentPage:
    name Content1.aspx
    Add this page with MasterPage.master page

    Tag Prefix will be like below

    <%@ Page Title="" Language="C#" MasterPageFile="MasterPage.master" AutoEventWireup="true" CodeFile="Content1.aspx.cs" Inherits="MasterPage" %>



    <asp:Content ID="Content2" ContentPlaceHolderID="head" Runat="Server">

    Add you styles and javascripts

    </asp:Content>

    try this and also refer some sites
    hopoe this will help you

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    Add your content Page Code here
    </asp:Content>

    try this and also refer some sites
    hopoe this will help you

    Paul.S

  • #767469
    To keep uniform look of all pages in application we can use master page, A single master page defines the look and feel and standard behavior that you want for all of the pages You can then create individual content pages that contain the content you want to display. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page.
    first you need to include @ Master directive at top of the page

    < asp:contentplaceholder id="Main" runat="server" />

    at page directive of contents page you need to specify master file name as below

    < %@ Page Language="C#" MasterPageFile="~/MasterPages/Master1.master" Title="Content Page"%>

    hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #767486
    Hi,

    Master is nothing but an application page but the difference is you can set this as head of those all application pages, there is no difference while creating master page and application page, how you design the application page in the same passion you can create master page too, but you have to inherit the same in child pages, first Google it for few samples then try to create it by your self.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #767507
    Hi,

    Master Pages are used to create generic structure for web application. Normally in sites we want Same Logo, and Menu Items, Footer, etc.. in all the pages. So we will create master page with the desired structure and make use of it in our application...

    We can create master page Soln explorer-> Add new item of project, there select master page.

    In master page we can put design and themes for the site.
    Master page have the option called content place holder.
    content place holder in that master page allows its child web page for its execution code part.
    Every web page was child to that master page.

    We can create more than one master page for a site and we can dynamically make particular master page as its for execution.

    After creating master form, while creating forms, Soln explorer-> Add new item of project,-> webform then you check the 'select master page'.
    SO it will offer the master forms if any in your project. you can select from the list if you created already.

    (OR)

    you have to give master page name, on which page you want master form.
    give likebelow..

    In the <%@ Page Language="C#" MasterPageFile="~/masterTeamLead.master"

    Refer the below Sample Example....

    Suppose master form Sample.master is:
    <head runat="server">
    <title></title> <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder></head><body>
    <form runat="server">
    <div class="page">
    <div class="header"><asp:Panel ID="Panel1" runat="server" BackColor="#FF3300" BorderColor="#FF66CC"> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    </asp:Panel>
    </div>
    <div class="main">
    <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
    </div>
    <div class="footer">
    <asp:Label ID="Label2" runat="server" Text="CopyRights@ssss"></asp:Label>
    </div> </form></body>

    After creating master form, while creating forms, Soln explorer-> Add new item of project,-> webform then you check the 'select master page'.SO it will offer the master forms if any in your project. you can select from the list if you created already.OR In child form add the master form to page directive....

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Sample.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %><asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"></asp:Content><asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></asp:Content>



    Hope this will giv u some idea

    Regards,
    SonyShiva
    Never lose hope..You never know what tomorrow will bring


  • Sign In to post your comments