This post is a quick one to post some SharePoint code. This post refers to the post posted by Eric Overfield. Refer to the post to get the full background, but he explains how the OnPreInit event method overrides any MasterPage assignment you might put on your Page Layout. He eludes to the fact that you can use reflector to see that the URL to a master page is overridden. I thought I would post the code. So you understand what is happening in the method and how you can set the master page url. It is a bit unclear in the his post which property needs to be set. It is not the CustomMasterUrl that you have to override. It is the MasterPageFile. In the SharePoint code, the MasterPageFile is overridden by CustomMasterUrl see bellow.
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
SPContext current = SPContext.Current;
if (current == null)
{
SPException exception = new SPException(Resources.GetString("ErrorInvalidSPContextCurrent"));
ULS.SendTraceTag(0x376f6233, ULSCat.msoulscat_CMS_Publishing, ULSTraceLevel.Unexpected, "PublishingLayoutPage.OnPreInit(): Exception: SPContext.Current is null");
throw exception;
}
SPWeb web = current.Web;
this.MasterPageFile = web.CustomMasterUrl;
}
This code was extracted from the Microsoft.SharePoint.Publishing.PublishingLayoutPage Class using Reflector.