Custom list definitions with custom forms – changing master page
As many of you might have experienced when you create your own custom list definition, you can also create your custom forms (DispForm.aspx
for example).
In my case, I want the DispForm.aspx to use another master page than it originally does, and so I thought I’d just change the following line of my DispForm.aspx
:
From:
<%@ Page language="C#" MasterPageFile="~masterurl/default.master" ... %\>
To:
<%@ Page language="C#" MasterPageFile="/_layouts/zTest/test.master" ... %\>
Problem
Doing this will most likely cause you to receive the following known error message:
An error occurred during the processing of . The referenced file ‘/_layouts/zTest/test.master’ is not allowed on this page.
Solution/Workaround
Instead of changing the MasterPageFile attribute of the Page directive, inject some server-side script in the DispForm.aspx in order to change the MasterPageFile property though code.
In your DispForm.aspx
, do the following:
-
Keep the MasterPageFile=”~masterurl/default.master” attribute
-
Insert the following server-side script directly undet the <%@ Page … %> directive:
-
Watch your DispForm.aspx use a new Master Page without getting the error message.
Thanks to
I’d like to shout out to MVP Eric Schupps for giving me this smart tip.