简体   繁体   English

从其他页面的ASP.NET母版页排除内容

[英]Excluding content from ASP.NET master page in other page

is it possible to exclude layout (header, sidebar and footer) from content page that inherit master page? 是否可以从继承母版页的内容页中排除布局(页眉,边栏和页脚)? I'm asking because of situation with repeated layout: 我要问的是由于布局重复的情况:

在此处输入图片说明

In master there is a structure like this: 在master中有这样的结构:

<body>
<!-- HEADER -->

<!-- Menu -->
<!-- CONTENT -->
<form enctype="multipart/form-data" id="form1" runat="server" autocomplete="off">
                                <div>
                                    <asp:contentplaceholder id="ContentPlaceHolder1" runat="server"></asp:contentplaceholder>
                                </div>
                            </form>
<!-- FOOTER -->
</body>

and in content page (.aspx) there is a structure 在内容页面(.aspx)中有一个结构

<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" Inherits="Site.WebBasePage"
    EnableEventValidation="false" JFormID="Form" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<j:Tab Name="Tab2" runat="server" ID="detail">
                <iframe class="embed-responsive-item" id="detail" frameborder="0" src="about:blank" width="100%" height="100%"></iframe>
            </j:Tab>

</asp:Content>

In the code above there is a call for another aspx file where is the detail form. 在上面的代码中,调用了另一个aspx文件,其中是详细信息表单。

You can hide content place holder which you dont want to display on your content page by below code 您可以通过以下代码隐藏不想显示在内容页面上的内容占位符

//get the master page of current page //获取当前页面的母版页

From here you can find the relevant place holder like this: 在这里,您可以找到相关的占位符,如下所示:

PlaceHolder objPlaceHolder = this.Page.Master.FindControl("PlaceHolderID") as PlaceHolder;
if(objPlaceHolder == null)
{
    // doesn't exist content place holder.
}
else
{
    objPlaceHolder.Visible = false;
}

This will hide the content place holder of master page in child page 这将在子页面中隐藏母版页的内容占位符

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

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