简体   繁体   English

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

[英]In nested master pages child master page code behind not working properly

In nested master pages child master pasge code behind not working properly.. 在嵌套的母版页中,子母版页背后的代码无法正常工作。

if i debug and set a stopper in child master page code behind file its not working.. 如果我调试并在文件后面的子母版页代码中设置了一个塞子,它将无法正常工作。

Following is my code: 以下是我的代码:

here is main master page html code 这是主主页的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>

here is the child master page html code 这是子母版页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>

code behind of master page 母版页后面的代码

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

code behind of child master page 子母版页后面的代码

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";
    }
}

Here in your child master place the controls outside the ContentPlaceHolder like, 在您的孩子母版中,将控件放置在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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM