【问题标题】:Web Form Not Inheriting Master Page on Microsoft Visual StudioWeb 窗体不继承 Microsoft Visual Studio 上的母版页
【发布时间】:2017-06-03 19:50:24
【问题描述】:

好的。我正在使用 Visual Web Developer 制作一个学校项目,我需要使用母版页。当我基于我的母版页创建一个新的 Web 表单时,它继承了母版页的颜色,但是有一个没有被继承的表格。这是我的母版页代码:

<%@ Master Language="VB" CodeFile="Master1.master.vb" Inherits="Master1" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server" background-color: #00FF00;>
        <title></title>
        <asp:ContentPlaceHolder id="head" runat="server">
        </asp:ContentPlaceHolder>
        <style type="text/css">
            .auto-style2 {
                height: 57px;
                width: 2363px;
            }
            .auto-style3 {
                height: 57px;
                width: 48px;
            }
            .auto-style4 {
                height: 48px;
            }
            .newStyle1 {
                background-color: #FF00FF;
            }
            .auto-style5 {
                width: 369px;
                height: 214px;
            }
        </style>
    </head>
    <body style="background-color: blue;">
        <form id="form1" runat="server">
        <div class="newStyle1">
            <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

                <table class="newStyle1">
                    <tr>
                        <td class="auto-style4" colspan="2">
                            <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal">
                                <Items>
                                    <asp:MenuItem NavigateUrl="Default.aspx" Text="Home" Value="Home"></asp:MenuItem>
                                    <asp:MenuItem NavigateUrl="About.aspx" Text="About" Value="About"></asp:MenuItem>
                                </Items>
                            </asp:Menu>
                        </td>
                    </tr>
                    <tr>
                        <td class="auto-style3">
                            <img alt="CS Logo" class="auto-style5" src="cSk.png" /></td>
                        <td class="auto-style2">
                            <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
                            </asp:ContentPlaceHolder>
                        </td>
                    </tr>
                    <tr>
                        <td class="auto-style4" colspan="2"></td>
                    </tr>
                </table>

            </asp:ContentPlaceHolder>
        </div>
        </form>
    </body>
    </html>

母版页 VB 代码:

Partial Class Master1
    Inherits System.Web.UI.MasterPage
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

    End Sub
End Class



 Web Form Attempted to Inherit Master Page:

%@ Page Title="" Language="VB" MasterPageFile="~/Master1.master" %>

<script runat="server">

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>

【问题讨论】:

  • 尝试将脚本放入ContentPlaceHolderID="head" ?
  • 谢谢。通过将表格移到 div 之外解决了我自己的问题。

标签: vb.net webforms master-pages


【解决方案1】:

如果您希望在后续子页面中覆盖此内容,则应仅将 HTML 元素放置在母版页的占位符内。

您的子页面的问题在于它用空 HTML 覆盖了包含表格的占位符。

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> </asp:Content>

如果您希望继承内容,请勿将共享内容放在占位符中。

如果您必须采用这种将共享内容放置在占位符中的做法,请不要在子页面中覆盖此内容。所以在你的例子中:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> </asp:Content>

将在母版页中显示表格。

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-24
    • 1970-01-01
    • 2019-12-30
    • 1970-01-01
    • 2011-11-16
    • 2011-11-18
    • 1970-01-01
    • 2012-03-18
    相关资源
    最近更新 更多