![](/img/trans.png)
[英]Only Content controls are allowed directly in a content page that contains Content controls in ASP.NET
[英]ASP.NET Error: Content controls are allowed only in content page that references a master page
由於以下頁面,我收到了標題中的錯誤:
<asp:Content ID="Content" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server">
<atlas:ScriptManager ID="ScriptManager" runat="server">
</atlas:ScriptManager>
在此頁面中,我使用 AJAX 控件。
您放置內容控件的頁面不是基於母版頁的頁面。 檢查頁面頂部,如果你有 html 喜歡
<html>
<body>
標簽那么可能是您創建了一個新頁面,而不是基於母版頁的新頁面。
我遇到了同樣的問題。
就我而言,需要遵循以下 3 個步驟來修復它:
MasterPageFile="~/MyBasePage.Master"
不存在此屬性,就像這樣。 確保屬性在那里。 <%@ Page Language="C#" MasterPageFile="~/MyBasePage.Master AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="Public.Home" %>
ContentPlaceHolder
來保存 HTML <asp:ContentPlaceHolder ID="ContentHeader" runat="server"></asp:ContentPlaceHolder>
ContentPlaceHolderID
與上述ID
相同<asp:Content ID="Content1" ContentPlaceHolderID="ContentHeader" runat="server"></asp:Content>
只要使用這些線,問題就會解決。
<%@ 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.