z
 
:: Home     :: MS Dynamics CRM     :: .Net 1.1     :: .Net 2.0     :: Sharepoint Portal     :: Ajax

  login:        
  passwords:  

Master Pages in Windows SharePoint Services 2.0

One of the most tedious aspects of customizing and branding sites in Windows SharePoint Services 2.0 is creating a consistent look and feel across pages. This is because ASP.NET 1.1 does not provide any suitable page templating technique that can be used across the pages within a Windows SharePoint Services 2.0 site. As a result, many developers and designers have resorted to copying and pasting HTML layouts from page to page. As you can imagine, this makes it very hard to customize and maintain a site whose layout requirements differ from the out-of-the box experience with a standard Windows SharePoint Services 2.0 site.

As you’re probably aware, ASP.NET 2.0 has introduced a powerful page templating feature known as master pages. A master page is a template that allows you to define a standard page layout for an entire site with elements such as a banner, navigation controls, and menus. The pages that link to a master page are known as content pages.

The key concept is that each content page links to the master page to get the shared layout, and then extends the master page by adding customized content to replaceable named placeholders.

Windows SharePoint Services 3.0 was designed from the ground up to embrace the master page infrastructure of ASP.NET 2.0. Every Windows SharePoint Services 3.0 site is provisioned with a special catalog known as the Master Page Gallery containing a master page named default.master. This master page defines a common layout for every site’s home page (Default.aspx) as well as all the standard Windows SharePoint Services form pages associated with lists and document libraries (for example, AllItems.aspx, NewItem.aspx). The master page layout includes standard Windows SharePoint Services menus and navigation controls.

The definition of default.master includes several different named placeholders such as Place- HolderPageTitle, PlaceHolderMain, and PlaceHolderLeftNavigation. This makes it relatively simple to create a new custom content page that has the same layout as the other pages in a site. Take a look at the simplicity of the content page definition shown in the following code.

 

The content page definition shown in the code could not be any simpler. It does nothing other than add a minimal fragment of HTML content inside PlaceHolderMain. However, it produces the standard Windows SharePoint Services page layout with site icons, menus, and navigation bars, as shown in Figure 1-3. Once you learn how to use the standard set of placeholders defined in default.master, you can easily swap out standard Windows SharePoint Services elements like menus and navigation bars and replace them with your own ASP.NET controls and Web Parts. This can be done for pages at the scope of a site, a site collection, or even on a farmwide basis.

Master pages and content pages are stored and loaded using the same concepts of page templates and page customization discussed earlier. There are page templates defined for the master page as well as for content pages that reside on the local file system of the front-end Web server. Each site initially uses an uncustomized (that is, ghosted) version of the master page template and content page templates. However, once a user customizes and saves one of these pages for a particular site using a tool such as Office SharePoint Designer 2007, a customized (unghosted) version is saved in the SQL Server database.

It’s possible to customize the master page for a site while leaving the content pages uncustomized. Likewise, it’s possible to customize one or more content pages while leaving the master page uncustomized. Furthermore, if you customize either the master page or a content page and later wish to undo your changes, both the browser-based UI of Windows SharePoint Services 3.0 and Office SharePoint Designer 2007 provide simple menu commands to discard customization changes from the SQL database and revert back to the original page template.

Figure 1-3 It’s easy to create custom content pages that use the standard Windows SharePoint
Figure 1-3 It’s easy to create custom content pages that use the standard Windows SharePoint Services layout.

You might have noticed in the code on previously that the content page shown in Figure 1-3 links to the master page using a special syntax in the form of ~masterurl/default.master. This is a tokenized reference to a master page that can be changed programmatically on a site-wide basis. You can accomplish this by acquiring an SPWeb reference to the current site and then updating the MasterUrl property.

Note that each site has its own Master Page Gallery with a default.master and its own Master- Url property. That means all the sites in a site collection do not automatically use the same master. However, with the use of recursion it’s pretty easy to write some code against the Windows SharePoint Services 3.0 object model to synchronize a top-level site and all the child sites in a site collection to use the same master pages.

 

In addition to ~masterurl/default.master, there is another dynamic token for master pages in the form of ~masterurl/custom.master. This dynamic token works in conjunction with the CustomMasterUrl property of a site and provides a secondary target master page that can be redirected programmatically. There are also two static master page tokens that start with either ~site or ~sitecollection. These static tokens allow you to hard-code a relative path to a master page from either the root of the current site or the root of the current site collection.

 

Google
 
-->

 

::  Home :: Services ::  Prices ::  Request Quote
Copyright 2007, Megasolutions Ltd