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

12

39

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

Ailssa answered 14/2, 2013 at 5:50 Comment(2)
You can try getting rid of that space... Maybe there is extra space and being treated as a LiteralTourane
Hi, I checked with this. But as it is working on local host, facing bit problem to find the solution.Ailssa
M
27

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
Maxson answered 14/2, 2013 at 5:57 Comment(0)
H
16

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.

Halfon answered 9/1, 2015 at 8:9 Comment(2)
This is a great reason to move off of web formsSelfreproach
This was my reason for the error, I had an extra space.Samphire
L
11

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 .

Loincloth answered 14/2, 2013 at 7:29 Comment(1)
Yes, I have separate head and body content. Also my code is inside content place holder. Still it is giving same error.Ailssa
P
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.

Pyriphlegethon answered 4/6, 2013 at 21:30 Comment(1)
This was my issue. I was using Visual Studio, so I just selected all to be commented then uncommented. This fixed it for me.Arieariel
M
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

Mouthful answered 21/1, 2014 at 12:46 Comment(0)
H
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.

Huppah answered 28/8, 2015 at 15:38 Comment(0)
H
4

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.

Headrick answered 11/6, 2019 at 13:53 Comment(1)
Editing in bitbucket directly caused this issue for us. Deleting the content and retyping it fixed the issue.Burkhardt
S
3

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.

Suzette answered 19/9, 2014 at 4:8 Comment(0)
M
3

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.

Marbleize answered 22/7, 2016 at 20:17 Comment(0)
I
2

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

When I add the reference the error disappeared.

Indifference answered 16/8, 2016 at 7:0 Comment(0)
S
2

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" %>
Scaly answered 17/5, 2019 at 15:54 Comment(0)
A
0

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

Alehouse answered 28/8, 2017 at 12:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.