UGTS Document #11 - Last Modified: 8/29/2015 3:23 PM
Debugging Nested Master Pages

If you try to use nested master pages in ASP.NET, where you have an overall master, a sub-master, and a page file, but the sub-master does not explicitly reference a master file to use, you may get the error message:

Content controls are allowed only in content page that references a master page.

This error message can be hard to understand because it looks like the compiler is choking on the page, because it is not correctly referencing the sub-master file. The real error here is that the sub-master file is missing an explicit master directive at the top to indicate that it is a master page (just using a file extension of .master is not enough, every master page must have a master directive), and therefore the contentplaceholder control there seems to be out of place to the ASP.NET compiler. The fix is to add the master directive to the top of the sub-master file like this:
 
<%@ Master Language="C#" MasterPageFile="/Default.master"%>  

Also note that when using nested master pages in Wisual Studio, the Design page in Visual Studio 2010 still has a lot of bugs. You may see that the designer ignores a master page directive in a web.config file in a subdirectory, even though the website runs as intended when running in the debugger. The workaround is to explicitly define the master page used by every page on the site, and not rely on a web.config file to set the master page.

Another problem that frequently happens with nested master pages is that the design view may show only a small block of HTML out of the total HTML on the page or it may stop displaying the page after a certain stopping point. Usually this occurs around block level tags such as div or ul. Web Expression 4 does not seem to have the problem. The workaround when this happens is to hand-code the HTML in the source pane of the Split view, and save the changes frequently to view how it looks in the Design pane (or use Web Expression instead of Visual Studio for HTML editing).