locked
How to use Custom Master Page for an Application Page? RRS feed

  • Question

  • Hi , How to use Custom Master Page for an Application Page? I have two master pages v4.master and my.master where v4.master is applicable to whole Application and my.master should be applicable to only my custom application page? Here is the code i have tried: protected void Page_Load(object sender, EventArgs e) { sing (SPSite oSite = new SPSite("url")) { using (SPWeb oWeb = oSite.OpenWeb("url")) { // Create full master url Uri masterUri = new Uri(curWeb.Url + "/_catalogs/masterpage/my.master"); string masterUrl = SPEncode.UrlDecodeAsUrl(masterUri.AbsolutePath); // Master page used by all forms and pages on site curWeb.MasterUrl = masterUrl; curWeb.CustomMasterUrl = masterUrl; curWeb.Update(); } } } Can anyone please suggest me how it can be done? Thanks!!!
    Wednesday, February 1, 2012 10:05 AM

Answers

  • Hello,

    Use the below code in the Pre_Init method of your custom application page

    protected void Page_PreInit(object sender, EventArgs e)
        {
            MasterPageFile = "/_catalogs/masterpage/my.master";
        }
    


     


    Ram Prasad Meenavalli | MCTS SharePoint 2010 | MCPD SharePoint 2010
    • Marked as answer by rihdus Wednesday, February 1, 2012 11:19 AM
    Wednesday, February 1, 2012 10:33 AM

All replies

  • You can change the master page url in the aspx of the page.

    <%@ Page language="C#" MasterPageFile="~masterurl/default.master"    Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document"  %>

     

    Change the bold text with your master page.


    Varun Malhotra
    =================
    Please Mark As Answer if my post solves your problem or Vote As Helpful if a post has been helpful for you.
    Wednesday, February 1, 2012 10:23 AM
  • Hello,

    Use the below code in the Pre_Init method of your custom application page

    protected void Page_PreInit(object sender, EventArgs e)
        {
            MasterPageFile = "/_catalogs/masterpage/my.master";
        }
    


     


    Ram Prasad Meenavalli | MCTS SharePoint 2010 | MCPD SharePoint 2010
    • Marked as answer by rihdus Wednesday, February 1, 2012 11:19 AM
    Wednesday, February 1, 2012 10:33 AM