在嵌套母版页中,后面的子母版页代码无法正常工作

时间:2012-11-23 21:49:23

标签: c# master-pages

在嵌套母版页中,子主密码后面的代码无法正常工作..

如果我调试并在文件后面的子母版页代码中设置一个塞子它不工作..

以下是我的代码:

这里是主页面主页html代码

<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="AdminMaster.master.cs"
Inherits="Admin_AdminMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
        <div class="mainouter">
            <div class="Contents">
                <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                </asp:ContentPlaceHolder>
            </div>
        </div>
    </form>
</body>
</html>

这里是子母版页面html代码

<%@ Master Language="C#" MasterPageFile="~/Admin/AdminMaster.master"
AutoEventWireup="false"
CodeFile="AdCommercialDetail.master.cs" Inherits="Admin_AdCommercialDetail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2"
ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <table style="width: 100%;">
        <tr>
            <td>
                <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
            </td>
            <td>
                fdgsdf
            </td>
            <td>
                dfgfdg
            </td>
        </tr>
    </table>
</asp:Content>

母版页后面的代码

public partial class Admin_AdminMaster : System.Web.UI.MasterPage {
    protected void Page_Load(object sender, EventArgs e)
    {
    }
}

子母版页后面的代码

public partial class Admin_AdCommercialDetail :
    System.Web.UI.MasterPage {
    SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase("ConnectionString");
    protected void Page_Load(object sender, System.EventArgs e)
    {
        this.Label1.Text = "gfjhfhggggggggggggggggg";
        Label1.Text = "fgdjgjhghklgfsaddffgghhjjkdsdfghjk";
    }
}

1 个答案:

答案 0 :(得分:0)

在您的孩子母版中,将控件放在ContentPlaceHolder之外,例如

<%@ Master Language="C#" MasterPageFile="~/Admin/AdminMaster.master"
AutoEventWireup="false"
CodeFile="AdCommercialDetail.master.cs" Inherits="Admin_AdCommercialDetail" %>
    <table style="width: 100%;">
        <tr>
            <td>
                <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
            </td>
            <td>
                fdgsdf
            </td>
            <td>
                dfgfdg
            </td>
        </tr>
    </table>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>

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