Custom list definitions with custom forms – changing master page

Tobias Zimmergren
Tobias Zimmergren

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.

SharePointCustomizationBranding

Tobias Zimmergren Twitter

Hey, I'm Tobias! I write about my experiences in designing, architecting, securing, and operating distributed cloud services. Nice to meet you 👋

Reactions and mentions


Hi, I'm Tobias 👋

Tobias Zimmergren profile picture

Find out more about me.

Recent comments

Recommended books!

Prepare for the AZ-500 exam!
Exam Ref AZ-500 Microsoft Azure Security Technologies
Azure Security Handbook!
Azure Security Handbook: A Comprehensive Guide for Defending Your Enterprise Environment
Prepare for the SC-900 exam!
Exam Ref SC-900 Microsoft Security, Compliance, and Identity Fundamentals