37

I have an application which has a master page and child pages. My application is working fine on local host (on my intranet). But as soon as I put it on a server that is on the internet, I get the error shown below after clicking on any menus.

Only Content controls are allowed directly in a content page that contains Content controls.

screenshot

Michael
  • 8,362
  • 6
  • 61
  • 88
Tripati Subudhi
  • 1,651
  • 10
  • 22
  • 26

12 Answers12

26

Double and triple check your opening and closing Content tags throughout your child pages.

Confirm that they

  • are in existence
  • are spelled correctly
  • have an ID
  • have runat="server"
  • have the correct ContentPlaceHolderID
Brian Webster
  • 30,033
  • 48
  • 152
  • 225
12

I had exactly the same issue. The problem was I had some spaces after the ending content tag:

</asp:Content>

Remove all the spaces, line breaks after the last closing tag.

Adrian Garcia
  • 788
  • 10
  • 14
10

I was facing a similar issue. Are you surrounding your code with the "content" tag ?

<asp:Content>Add your HTML here</asp:Content> 

And have separate content tags for your sections . A head content for the header declaration and a body content for the body declaration .

Mohammed Aamir K
  • 311
  • 5
  • 17
9

Another possibilty is line endings. I copied an older version of code from source control which enforced Unix style line endings. Since it wasn't a checkout, it didn't automatically convert the line endings to the DOS/Windows style. The error message was the "Only Content controls are allowed directly ..." error even though the page was layed out properly. It appears that the lack of Windows style line breaks caused the ASPX parser to fail.

I was able to fix it by pasting the code into a line ending agnostic editor (which caused the line endings to be normalized to the Windows style), re-copying it to the clipboard and pasting it back in Visual Studio, after which the page processed without errors.

In the case presented by Tripati Subudhi in the question, it's entirely possible that something about the deploy process used inadvertently converted line endings to the Unix style, leading to the error.

jball
  • 24,791
  • 9
  • 70
  • 92
6

Another possible issue is HTML comments, I had these surrounding a Content control - I believe ASP.NET converts these into literal controls behind the scenes - hence the error i

user369142
  • 2,575
  • 1
  • 21
  • 9
5

another potential cause for this error: tags with the wrong case.

changing <asp:content>... to <asp:Content>... fixed the issue in my case.

the reason for the faulty case was the built-in format document function in visual studio 2012(and 2013) with default settings. the setting for this can be changed in Tools->Options->Text Editor->HTML (Web Forms)->Formatting: set the tag capitalization to 'as entered' and studio will no longer destroy your files.

garglblarg
  • 576
  • 1
  • 8
  • 16
3

Check your document for non-printing characters

My masterpage contained two UTF-8 BOMs right at the start of the file because I pasted the <%@ Master %> directive from another page. I was able to make it work by backspacing them out.

mm201
  • 526
  • 4
  • 15
2

For me, it didn't like that I had an Assembly and a Page directive commented out:

<%--<%@ Assembly Name="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" %>--%>
<%--<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyPage.aspx.cs" Inherits="MyClass.MyPage" MasterPageFile="~/_layouts/MyProject/MasterPages/MasterPage.master" %>-->

Even though I had a valid Page directive after that, and was not using System.Core for anything. After just removing them, it loaded fine.

vapcguy
  • 7,097
  • 1
  • 56
  • 52
2

For me it was two content controls that had the same ID - the file had been edited outside of Visual Studio, so the auto-rename of duplicate ID didn't happen. This misleading error was highlighting the first image inside the second content control with the same ID as the first - what a wild goose chase!

Copying the entire page and reposting it over itself solved it, because VS at that point then renamed the duplicate control ID.

ITFlyer
  • 21
  • 1
1

In my case I forgot to add assembly reference of AjaxControlToolkit.dll.

When I add the reference the error disappeared.

Sumit Jambhale
  • 565
  • 8
  • 13
0

in SharePoint it happened since a pageLayout wasn't published.

bresleveloper
  • 5,940
  • 3
  • 33
  • 47
0

I had a silly syntax error I kept overlooking. There was an extra < at the start of my MasterType tag I couldn't see for the life of me ‍♂️.

<%@ Page Language="vb" AutoEventWireup="true" MasterPageFile="~/Site1.Master" CodeBehind="Default.aspx.vb" Inherits="SomeApp.Web._Default" %>

<<%@ MasterType VirtualPath="~/Site1.Master" %>
spottedmahn
  • 14,823
  • 13
  • 108
  • 178