Customizing Sharepoint Master Page

Developed a master page from scratch which can be intigrated with Sharepoint.

Developed a master page from scratch which can be intigrated with Sharepoint.

Problem this article addresses
Customizing the master page of a Sharepoint site.

Code Snippet
Declaration Section
<%-- Identifies this page as a .master page written in Microsoft Visual C#,
and registers tag prefixes, namespaces, assemblies, and controls. --%>
<%@ Master language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls"
Assembly="Microsoft.SharePoint.Portal, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
Assembly="Microsoft.SharePoint, Version=, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls"
Assembly="Microsoft.SharePoint.Publishing, Version=, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation"
Assembly="Microsoft.SharePoint.Publishing, Version=, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="wssuc" TagName="Welcome" src="~/_controltemplates/Welcome.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="DesignModeConsole" src="~/_controltemplates/DesignModeConsole.ascx" %>
<%@ Register TagPrefix="PublishingVariations" TagName="VariationsLabelMenu" src="~/_controltemplates/VariationsLabelMenu.ascx" %>
<%@ Register Tagprefix="PublishingConsole" TagName="Console" src="~/_controltemplates/PublishingConsole.ascx" %>
<%@ Register TagPrefix="PublishingSiteAction" TagName="SiteActionMenu" src="~/_controltemplates/PublishingActionMenu.ascx" %>
<%-- Uses the Microsoft Office namespace and schema. --%>.

Add any user controls (.ascx files) to the controltemplates directory.

Declaration for custom controls
<%@ Register TagPrefix="MyCustomNav" TagName="Navigation" Src="~/_controltemplates/ MyCustNav.ascx" %>
<%@ Register TagPrefix="MyCustomFooter" TagName="Footer" Src="~/_controltemplates/MyCustFooter.ascx" %>

In the header section, you can add any custom cascading styles sheets by using a simple link <html> tag or <SharePoint:CssRegistration> tag. The latter approach offers a few advantages because you have an option to use SPUrl, which returns the URL of the current site.

Header Part

  <WebPartPages:SPWebPartManager runat="server"/>
  <SharePoint:RobotsMetaTag runat="server"/>

  <%-- The head section includes a content placeholder for the page title and links to CSS and ECMAScript (JScript, JavaScript)
     files that run on the server. --%>
  <head runat="server">
    <asp:ContentPlaceHolder runat="server" id="head">
        <asp:ContentPlaceHolder id="PlaceHolderPageTitle" runat="server" />
    <Sharepoint:CssLink runat="server"/>
    <!-- Product Group Custom Styles -->
    <%--SharePoint:CssRegistration name="<% $SPUrl:~SiteCollection/Style Library/PG/PG.css%>" runat="server"/--%>
    <link type="text/css" rel="stylesheet" href="/_layouts/1033/styles/PG/PG.css" />    
    <!-- End Product Group Custom Styles -->
    <asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server" />
Copy and add the following code. The body section consists of the main body including the Site Actions menu, logon control, publishing console control, any navigation controls, and the main content placeholder or content area, which are defined by layouts.
<%-- When loading the body of the .master page, Office SharePoint Server 2007 also loads the SpBodyOnLoadWrapper class. This class handles .js calls
   for the master page. --%>
  <body onload="javascript:_spBodyOnLoadWrapper();">
    <%-- The SPWebPartManager manages all of the Web part controls, functionality, and events that occur on a Web page. --%>
    <form id="Form1" runat="server" onsubmit="return _spFormOnSubmitWrapper();">
        <!-- Master DIV -->
    <div id="masterbody">
        <!-- Master Header -->
        <div id="MasterHeader">
            <div class="authoringRegion1">
                <div class="sharepointLogin"><wssuc:Welcome id="explitLogout" runat="server"/></div>
                <span class="siteActionMenu"><PublishingSiteAction:SiteActionMenu runat="server"/></span>
                   id="authoringcontrols" runat="server">
                      <PublishingConsole:Console runat="server" />
        <!-- Left Body for Navigation -->
        <div id="LeftNavBody"><asp:ContentPlaceHolder
           id="PlaceHolderLeftNavBar" runat="server"/>
        <div id="leftnavspacer"><!-- Spacer -->
        <!-- Content Body -->
        <div id="StagingBody">            
              <asp:ContentPlaceHolder id="PlaceHolderMain" runat="server" />            
        <!-- Footer Area -->
        <div id="Footer"></div>

Copy and add the following code. This section is generally not visible but consists of placeholders that Office SharePoint Server needs to work properly. You can also use a <div> tag with display:none to hide this section instead of using a panel.
<%-- The PlaceHolderMain content placeholder defines where to place
the page content for all the content from the page layout. The page
layout can overwrite any content placeholder from the master page.
Example: The PlaceHolderLeftNavBar can overwrite the left navigation bar. --%>
        <asp:Panel visible="false" runat="server">
        <%-- These ContentPlaceHolders ensure all default Office SharePoint Server pages
render with this master page. If the system master page is set to
any default master page, the only content placeholders required are
those that are overridden by your page layouts. --%>
            <asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server"/>
            <asp:ContentPlaceHolder id="PlaceHolderTitleBreadcrumb" runat="server"/>
            <asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea"  runat="server"/>            
            <asp:ContentPlaceHolder ID="PlaceHolderPageImage" runat="server"/>
            <asp:ContentPlaceHolder ID="PlaceHolderBodyLeftBorder" runat="server"/>
            <asp:ContentPlaceHolder ID="PlaceHolderNavSpacer" runat="server"/>
            <asp:ContentPlaceHolder ID="PlaceHolderTitleLeftBorder" runat="server"/>
            <asp:ContentPlaceHolder ID="PlaceHolderTitleAreaSeparator" runat="server"/>
            <asp:ContentPlaceHolder ID="PlaceHolderMiniConsole" runat="server"/>
            <asp:ContentPlaceHolder id="PlaceHolderCalendarNavigator" runat ="server" />
            <asp:ContentPlaceHolder id="PlaceHolderLeftActions" runat ="server"/>
            <asp:ContentPlaceHolder id="PlaceHolderPageDescription" runat ="server"/>
            <asp:ContentPlaceHolder id="PlaceHolderBodyAreaClass" runat ="server"/>
            <asp:ContentPlaceHolder id="PlaceHolderTitleAreaClass" runat ="server"/>
            <asp:ContentPlaceHolder id="PlaceHolderBodyRightMargin" runat="server"/>

By Devil Scorpio   Popularity  (3296 Views)