Quantcast
Channel: Development With A Dot
Viewing all articles
Browse latest Browse all 404

SharePoint Pitfalls: Master Pages in Page Layouts

$
0
0

When you deploy a page layout, you may want to add your own master page as well. I find it useful to add my own custom master pages and reference them directly, in the same or a dependent feature. You might be surprised, however, that it doesn’t work exactly how you’d expect!

The issue is, page layouts will ignore silently anything in the MasterPageFile attribute if it isn’t one of the standard tokens for the system or custom master pages. ~masterurl/default.master and ~masterurl/custom.master. The solution is to have a code behind class and specify the master page in the OnPreInit method (anywhere else won’t work):

protectedoverridevoid OnPreInit(EventArgs e)
{
base.OnPreInit(e);
 
this.MasterPageFile = "~site/_catalogs/masterpage/CustomMasterPage.master":
}


Viewing all articles
Browse latest Browse all 404

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>