If, like me, you are so unlucky to encounter the infamous:
‘The page has one or more <asp:Content> control that do not correspond with <asp:ContentPlaceHolder> control in master page.’
Figure 1 - The designer showing the master page error
error message when dealing with Asp.Net pages that actually use a master page, and you are unable to use the designer to drop and configure controls (raise your hand if you still use the designer instead of doing everything by hand!) you can do the following thing:
- go for the obvious resolution and check for the names of the content place holders.
If the problem still persists and you’re sure your content controls and content place holders are correctly mapped to each others (you can let the wizard generate the page for you) and moreover everything actually works at runtime (even the designer for the master page works!), the error is surely somewhere in the HTML markup and this very informative error message won’t help you find it out.
I started looking at the markup and everything seemed ok to me, even a friend of mine confirmed me the markup was ok...until I started looking very carefully and spotted the problem: this page was derived from an old project and maintained by lot of persons...so it ended having some markup and HUGE portions of the page commented out, the master page had some code like this:
... <div id="divCentralBlock"> <div id="header_down"> </div> <div class="line"> </div> <%-- Breadcrumb --%> <%-- <div id="SiteMap_Contenitore"> <asp:SiteMapPath ID="MainSiteMapPath" runat="server" PathSeparator=" : " CssClass="fnsize76pr" CurrentNodeStyle-CssClass="currentNode" NodeStyle-CssClass="node" SiteMapProvider="SiteMapPath" meta:resourcekey="MainSiteMapPathResource1" Visible="false" Enabled="false"> <CurrentNodeStyle CssClass="currentNode" /> <NodeStyle CssClass="node" /> </asp:SiteMapPath> <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" /> <%-- <cc1:scriptmanager id="smAtlas" runat="server"></cc1:scriptmanager> --%> <%-- </div> ... a lot more commented code wiped out --%> <div id="contentBox"> <div id="contentTitle"> <asp:ContentPlaceHolder ID="TitlePlaceHolder" runat="server"> </asp:ContentPlaceHolder> </div> <div id="contentBody"> <div> <asp:ContentPlaceHolder ID="MainPlaceHolder" runat="server"> </asp:ContentPlaceHolder> </div> </div> </div> </div> ...
As you can see lines 7 to 18 contain a lot of comments, the visual studio html syntax verifier does not complain about everything when looking at this code, but if you look carefully at the end of line 14 you can see the missing of a close comment tag ( --%> ), neither me nor my friend saw this problem because at our first look WE SKIPPED THE COMMENTED COMPLETELY, giving it for granted that they couldn’t cause any trouble (what a mistake!).
This lack was causing a lot of troubles to the designer that wasn’t able to parse the master page correctly. Closing the comment in the correct way solved the problem and we were able to use the master page in the designer again; the lesson is: always respect the syntax of the language you’re using! (and always look at everything when things don’t work as expected).
- WebNet European Conference, Slides and Samples (11/06/2012)
- ASP.NET - Tagging and Hiding the columns of a GridView (26/08/2015)
- Working on Dexter (26/08/2015)
- Visual Studio 2010 designer error: Value cannot be null. Parameter name: objectType (26/08/2015)
- More related document (10)