Only Content Controls are Allowed (C# webcontrols)
Asked Answered
C

1

6

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!";
                    }
            }
    }
}
Counterbalance answered 22/1, 2013 at 20:44 Comment(0)
K
10

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>
Kerstin answered 22/1, 2013 at 20:50 Comment(2)
Yeah it can be annoying =] it makes sense though if you think about it, where should that <h2> go in the page if it's outside a content place holder in the master page; at the beginning of the body, the end, wherever the render is at when it encounters it? It's just knowing the paradigm is all ^_^Kerstin
That does make sense. x.x. Thanks for being so nice~! I'll mark this correct when it lets me!Counterbalance

© 2022 - 2024 — McMap. All rights reserved.