Search This Blog

Thursday, September 18, 2014

Share Point Master page

What are different types of master pages in SharePoint 2010?


There are basically three types of pages in SharePoint for which we have a corresponding master page, which are as follows:
  • Publishing Pages - these are those pages that are there in the Site Pages document library for e.g. default.aspx --- so we have the Site Master for these kinds of pages.
  • Forms and Views Pages - these are the pages used to view the data stored in the lists and document libraries for e.g. AllItems.aspx --- so we have System Master for these kinds of pages.
  • Application Pages - these are the pages that are stored in the _layouts folder in the server, these are the pages that are used for settings etc. --- so we have Application Master for these kinds of pages.
The different types of master pages that are available in SharePoint 2010 are as follows:
  1. v4.master - this is the default master page
  2. default.master - this is a master page that provides backward compatibility with MOSS 2007
  3. minimal.master - 
  4. simple.master - this is used for the accessdenied, sign out, login, error pages etc.


What are Master Pages in .NET? Why we need Master Pages and how do we use Master Pages in our applications?

Life before Master Pages
For a given website, there are multiple web pages with common layout. How we can achieve this?
  • Write the layout of the code in each page. But this leads to code redundancy which is not correct.
  • We can achieve the common layout, by using User controls.
Advantage of User Controls:
  • Turning an existing ASP.NET page into a user control requires only a few minor changes. User controls can be easily linked to any page that needs their services.
  • Furthermore, changes to a user control's implementation do not affect the referencing page and only require recompiling of the user control into an assembly.
Disadvantage of User Controls:
  • Any alteration to the control's public interface (such as the class name, properties, methods, or events) leads to the pages that reference the control must be updated.
  • Those pages must be re-compiled and needs deployment.
  • In addition, the next time a user views each page, the ASP.NET runtime will take a while to respond because the dynamic assembly for the page must be re-created.
Apart from the above two options, the other options is to use Master pages. A Master page is a file that contains the static layout of the file. It consists of the layout that is common throughout application (i.e. Application Level) or a folder level and dynamic parts will be customized by the pages that are derived from the Master page.
What is a Master Page?
One of the cool new things introduced in ASP.NET 2.0 is Master Pages. Master Pages give you the ability to define a master page layout and look that is used throughout a site to give a consistent look & feel to all pages. Any updates or changes to the look & feel of the site is done in only one place - the Master Page.
A master page is similar to an ordinary ASP.NET page except for the top @Master directive and the presence of one or more ContentPlaceHolder server controls. A ContentPlaceHolder
control defines a region in the master page that can be customized in a derived page. ContentPlaceHolder acts as container which holds controls/items defined in the derived pages.
<asp:contentplaceholder runat="server" ID="PageBody" />
In the derived pages, server control <asp:Content> is used to provide actual content to ContentPlaceHolders of Master Page. The link between placeholders and content is established through the Content place holder ID.
<asp:Content runat="server" contentplaceholderID="PageBody">
...</asp:Content>
Apply Custom Master Pages in SharePoint 2010

First you have to enable the Publishing feature

Site Actions > Site Settings > Site Actions section > Manage Site Features
SharePoint Server Publishing > Click on Activate

Now create a  Custom Master Page

Site Actions > Edit in SharePoint Designer
In SharePoint Designer
  1. Select your site
  2. Click on Master Pages on the left
  3. In the Ribbon click on Blank Page Master
  4. Name appropriately
  5. Download Randy Driscoll’s Starter Master Pages for SharePoint 2010http://startermasterpages.codeplex.com/
  6. Unzip and copy the Foundation (foundation) or SharePoint Server (publishing) version of the master page, depending on your installation, and paste into your new master page content.
  7. save the custom master page
Note: You can also duplicate a master page by right clicking on the listing, then using copy and paste.

Make new master page available

Site Actions > Site Settings > Galleries > Master pages and page layouts
Click on master page to select the row
In the ribbon, click on “Check In” if it is available
In the ribbon, click on “Approve/Reject” to approve your new master page for use
If the “Compatible UI Version(s)” field does not have the correct UI(s), click on the Edit Properties in the ribbon and add or change the UI Version (3 is if you are using the legacy UI, usually from an upgrade – 4 is for the new 2010 UI)

Apply your custom master page

Site Actions > Site Settings > Look and Feel > Master Page (available now that publishing has been enabled)
Site Master Page > Specify a master page > select custom master page
Note: This is used by publishing pages, select reset all subsites if you like!
System Master Page > Specify a master page > select custom master page
Note: This is used by forms, “view” pages and pretty much everything that is not a publishing page on your site. Select reset all subsites if you like!
Alternate css url > specify a css file > browse and select the css file

No comments:

Post a Comment