Wednesday, 26 October 2016

How to refer a custom master page from a SharePoint Application page?


To refer a custom master page from an application page you should put both the files under the same layout folder in your SharePoint farm solution.

Then you can refer to the master page using the following tag from the application page:

MasterPageFile="MasterPages/MyCustomMaster.master"


Workaround to refer master page gallery from an application page:

protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
SPWeb web= SPControl.GetContextSite(Context).OpenWeb();
string strUrl = web.ServerRelativeUrl + “/_catalogs/masterpage/MyCustomMaster.master”;
this.MasterPageFile = strUrl;
}

No comments:

Post a Comment