仅允许内容控件(C# Web 控件)

本文关键字:控件 Web 许内容 | 更新日期: 2023-09-27 17:55:22

所以,我不确定发生了什么。我的老板对我使用 MVC 和 Razor 不满意,所以我被迫使用这种讨厌的 webcontrol/code隐藏风格进行编码。=/

错误是:

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

这是母版页:

<%@ 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>

这是引发错误的 Default.aspx 页面。

<%@ 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>

还有愚蠢的默认.aspx.cs代码隐藏...

使用系统;使用系统网;使用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!";
                    }
            }
    }
}

仅允许内容控件(C# Web 控件)

您的

所有内容(包括静态 HTML)都必须位于内容页面的 Content 标记内。你在外面有一个<h2>

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

应该是:

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