ASP.Net 嵌套母版页 - 您可以嵌套多深?

问题描述

这很长,所以请耐心等待。我只是想尽可能完整地说明情况...

关于 ASP.Net 中的母版页 - 我知道您可以嵌套母版页,并且您可以在同一级别具有多个嵌套母版页(顶级母版作为“父”和多个“子”,是一级嵌套母版页)。您能否在嵌套母版页(到“孙子”嵌套母版页)中深入一层以上,并且仍然能够使用“Master.Master.Master”语法到达顶级母版页的链?

情况: 我正在开发一个 C# ASP.Net 应用程序。我有三个母版页:Site.master(站点的顶级母版页)、SiteWizard.master(嵌套从 Site.master)和 WizardTransactionDriver.master(嵌套自 SiteWizard.master 的母版页)。>

相关标记如下:

Site.master:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="RegE_BranchV3.SiteMaster" %>
<body>
    <form runat="server">
        <div class="container body-content">    
            <asp:ContentPlaceHolder ID="MainContent" runat="server">
            </asp:ContentPlaceHolder>
            
            <asp:ContentPlaceHolder ID="WizardContent" runat="server">
            </asp:ContentPlaceHolder>
        </div>
    </form>
</body>

SiteMaster.cs

namespace SomeNameSpace
{
    public partial class SiteMaster : MasterPage
    {

        #region ===== Properties ====

        public TLoginSession LoginSession { get; set; }
    }
}

SiteWizard.master - 嵌套在 Site.Master 下

    <%@ Master Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="SiteWizard.master.cs" Inherits="RegE_BranchV3.SiteWizard" %>

<%@ MasterType VirtualPath="~/Site.Master" %>

<asp:Content ID="WizardAnswers" ContentPlaceHolderID="MainContent" runat="server">
    <asp:ContentPlaceHolder ID="WizardQuestions" runat="server">
    </asp:ContentPlaceHolder>
    <asp:ContentPlaceHolder ID="TransactionEntry" runat="server">
    </asp:ContentPlaceHolder>
</asp:Content>

AffidavitWizardText.aspx - 链接到 SiteWizard.master 的内容页

<%@ Page Title="" Language="C#" MasterPageFile="~/SiteWizard.Master" AutoEventWireup="true" CodeBehind="AffidavitWizardText.aspx.cs" Inherits="RegE_BranchV3.WebPages.AffidavitWizardText" %>

<%@ MasterType VirtualPath="~/SiteWizard.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="WizardQuestions" runat="server">
</asp:Content>

和 AffidavitWizardText.aspx.cs 中的代码隐藏:

namespace somenamespace
{
    public partial class AffidavitWizardText : System.Web.UI.Page
    {
        private TBranchSession fBranchSession;
        private IBranchCase2 fBranchCase;
        private TLoginSession fLoginSession;

        protected void Page_Load(object sender,EventArgs e)
        {
            Master.Master.LoginSession = TApplLib.LoadLoginSession(Session);
        }
    }
}

Master.Master.LoginSession 参考工作正常。

WizardTransactionDriver.master:

<%@ Master Language="C#" MasterPageFile="~/SiteWizard.Master" AutoEventWireup="true" CodeBehind="WizardTransactionDriver.master.cs" Inherits="RegE_BranchV3.WebPages.WizardTransactionDriver" %>

<%@ MasterType VirtualPath="~/SiteWizard.Master" %>   <%--SiteWizard--%>

<asp:Content ID="Content1" ContentPlaceHolderID="WizardQuestions" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="TransactionEntry" runat="server">
    
    <asp:ContentPlaceHolder ID="TransactionItem" runat="server">
    </asp:ContentPlaceHolder>
</asp:Content>

我有一个内容页 WizardTransactionText.aspx - 它的母版页是 WizardTransactionDriver.master

<%@ Page Title="" Language="C#" MasterPageFile="~/WebPages/WizardTransactionDriver.master" AutoEventWireup="true" CodeBehind="WizardTransactionText.aspx.cs" Inherits="RegE_BranchV3.WebPages.WizardTransactionText" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TransactionItem" runat="server">
</asp:Content>

WizardTransactionText.aspx.cs - 内容页代码隐藏:

namespace somenamespace
{
    public partial class WizardTransactionText : System.Web.UI.Page
    {
        private TBranchSession fBranchSession;
        private IBranchCase2 fBranchCase;
        private TLoginSession fLoginSession;
        protected void Page_Load(object sender,EventArgs e)
        {
            Master.Master.Master.LoginSession = TApplLib.LoadLoginSession(Session);
        }
    }
}

Visual Studio 无法识别上面的 Master.Master.Master.LoginSession 引用并给我一个错误。它识别在母版页嵌套的第一级绑定到 SiteWizard.master 的更高级别内容页面 AffidavitWizardText 中的 Master.Master.LoginSession 引用。为什么它不能识别嵌套嵌套引用?您可以嵌套母版页的级别(多深)有限制吗?

this thread 中,bkaid 说“您可以嵌套任意数量的母版页”。这可以采取几种方式。他链接到的文章中的示例仅显示了母版页的一级嵌套。我见过的每篇文章和示例都只显示了一级母版页嵌套。即使在解决方案资源管理器中添加项目时我可以创建多个级别的嵌套母版页,是否有一些幕后限制代码识别的级别数?我们在这里没有大量的 ASP.net 经验 - 是否还有我们遗漏的其他问题,或者其他途径?

感谢您的帮助和见解!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)