1

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

如果我在文件后面的子母版页代码中调试并设置一个停止器,它不起作用..

以下是我的代码:

这是主要的母版页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";
    }
}
4

1 回答 1

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>
于 2012-11-23T23:28:52.873 回答