Only Content Controls are Allowed (C# webcontrols)

user798080 picture user798080 · Jan 22, 2013 · Viewed 20.9k times · Source

So, I'm not sure what's going on. My boss wasn't pleased with me using MVC and Razor, so I'm being forced to code with this nasty webcontrol/codebehind style. =/

The error is:

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

Here is the masterpage:

<%@ Master Language="C#"%>
<!DOCTYPE html>
<html>
<head>
    <title>Application Form</title>
</head>
 <body>
    <div id="container">
        <asp:contentplaceholder id="contentPlaceHolder" runat="server" />
    </div>
</body>
</html>

And here is the Default.aspx page that's throwing the error.

<%@ Page Language="C#" Inherits="dumb.Default" MasterPageFile="MasterPage.master" %>

<h2>Application Form</h2>
<asp:Content id="content" ContentPlaceHolderID="contentPlaceHolder" runat="server">
    <p>Please complete this application.</p>

    <form action="Default.aspx" method="post" runat="server">
            <div>
                    <span class="spaced">Name:</span><asp:TextBox id="name" runat="server" />
            </div>
    </form>
    <p>
            <asp:Label id="finalmessage" runat="server" />
    </p>
</asp:Content>

And the silly Default.aspx.cs codebehind...

using System; using System.Web; using System.Web.UI;

namespace dumb
{
    public partial class Default : System.Web.UI.Page
    {
            protected void Page_Load (object sender, EventArgs e)
            {
                    if (IsPostBack) {
                            finalmessage.Text = "Submission Processed Successfully!";
                    }
            }
    }
}

Answer

Sean Airey picture Sean Airey · Jan 22, 2013

All of your content, including static HTML must be inside Content tags in the content page. You have a <h2> outside:

<h2>Application Form</h2>
<asp:Content id="content" ContentPlaceHolderID="contentPlaceHolder" runat="server">

Should be:

<asp:Content id="content" ContentPlaceHolderID="contentPlaceHolder" runat="server">
    <h2>Application Form</h2>