Web窗体不在Microsoft Visual Studio上继承母版页

时间:2017-06-03 19:50:24

标签: vb.net webforms master-pages

好的。我正在使用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>

Master Page

1 个答案:

答案 0 :(得分:1)

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

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

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

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

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

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

将在母版页中显示该表。

希望有所帮助。