c# - 仅允许内容控件(C# webcontrols)

标签 c# asp.net master-pages code-behind web-controls

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

错误是:

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>

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

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

最佳答案

您的所有内容,包括静态 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>

关于c# - 仅允许内容控件(C# webcontrols),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14467650/

相关文章:

c# - 从类文件访问母版页属性

c# - 我在我的一个网络表单上添加了一个 css,但它只适用于我的母版页,而不适用于特定的网络表单

c# - C#中的TCP监听器启动异常

c# - 如何在选项卡控制选项卡内嵌套多个组框?

c# - 有没有办法将 NAudio.Lame 与 Xamarin (Android/iOS) 应用程序一起使用?

c# - 从已编译的 DLL 中获取所有 XAML 文件

asp.net - 有没有办法在 asp.net 中使用 web.config 设置字符集?

javascript - JavaScript 中的文本框值

ASP.NET WebForms : Why do relative paths within user controls work locally, 但部署时不是?

c# - 使用主页时在网页上设置背景图片