Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 517
Tripati Subudhi Avatar asked Feb 14 '13 05:02

Tripati Subudhi


4 Answers

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
like image 73
Brian Webster Avatar answered Sep 20 '22 10:09

Brian Webster


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.

like image 43
Adrian Garcia Avatar answered Sep 19 '22 10:09

Adrian Garcia


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 .

like image 10
Mohammed Aamir K Avatar answered Sep 23 '22 10:09

Mohammed Aamir K


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.

like image 9
jball Avatar answered Sep 23 '22 10:09

jball