简体   繁体   English

ASP.NET 错误:仅在引用母版页的内容页中允许使用内容控件

[英]ASP.NET Error: Content controls are allowed only in content page that references a master page

I received the error in the title as a result of the following page:由于以下页面,我收到了标题中的错误:

<asp:Content ID="Content" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server">
<atlas:ScriptManager ID="ScriptManager" runat="server">
</atlas:ScriptManager>

In this page I use AJAX controls.在此页面中,我使用 AJAX 控件。

The page that you've put the content control is not a master page based page.您放置内容控件的页面不是基于母版页的页面。 Check the top of the page, if you've got html like检查页面顶部,如果你有 html 喜欢

<html>
<body>

tags then the likelihood is that you've created a new page rather than a new page based off a masterpage.标签那么可能是您创建了一个新页面,而不是基于母版页的新页面。

I ran into the same issue.我遇到了同样的问题。

For my case, these 3 steps needs to be followed to fix it:就我而言,需要遵循以下 3 个步骤来修复它:

  1. The .aspx file doesn't come under a MasterPage which means that this attribute is absent in the .aspx file MasterPageFile="~/MyBasePage.Master" like this. .aspx 文件不在 MasterPage 下,这意味着 .aspx 文件MasterPageFile="~/MyBasePage.Master"不存在此属性,就像这样。 Make sure the attribute is there.确保属性在那里。

<%@ Page Language="C#" MasterPageFile="~/MyBasePage.Master AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="Public.Home" %>

  1. The Master page needs to have the same ContentPlaceHolder like this to hold the HTML母版页需要像这样具有相同的ContentPlaceHolder来保存 HTML

<asp:ContentPlaceHolder ID="ContentHeader" runat="server"></asp:ContentPlaceHolder>

  1. The .aspx file needs to have a Content tag with the ContentPlaceHolderID same as the above ID .aspx 文件需要有一个 Content 标签,其ContentPlaceHolderID与上述ID相同

<asp:Content ID="Content1" ContentPlaceHolderID="ContentHeader" runat="server"></asp:Content>

Just use those lines, problem will be solved.只要使用这些线,问题就会解决。

<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="YourPageCode.aspx.cs" Inherits="ProjectName.PageName" %>
<asp:Content ID="ContentId" ContentPlaceHolderID="PlaceholderID" runat="server">Your page content here</asp:Content>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 只允许内容控件直接在包含ASP.NET中的内容控件的内容页面中 - Only Content controls are allowed directly in a content page that contains Content controls in ASP.NET asp错误:内容控件必须是内容页或引用母版页的嵌套母版页中的顶级控件 - asp error: Content controls have to be top-level controls in a content page or a nested master page that references a master page 样式表仅适用于asp.net中母版页的内容页 - Style sheets only for the content page of a Master page in asp.net 如何从 asp.net 中的母版页访问内容页面控件 - How to access content page controls from master page in asp.net 无法从内容页面在asp.net母版页控件中设置标签文本 - Not able to set label text in asp.net master page controls from content page 错误:在包含内容控件的内容页面中只允许直接使用内容控件。 在页面布局 SharePoint 2016 中 - Error: Only Content controls are allowed directly in a content page that contains Content controls. in Page Layout SharePoint 2016 直接在包含内容控件的内容页面中仅允许内容控件 - Only Content controls are allowed directly in a content page that contains Content controls 只允许在包含内容控件的内容页面中直接使用内容控件 - Only content controls are allowed directly in a content page that contains content controls 内容控件必须是内容页面中的顶级控件或引用母版页的嵌套母版页 - Content controls have to be top-level controls in a content page or a nested master page that references a master page asp.net中的母版页和内容页面通信 - Master page and content page communication in asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM