简体   繁体   中英

Get the name of the page in the content place holder of the Master Page

My Master page consists of a top bar that contains a few buttons and also a left menu bar by which the user can navigate through the web application. My Login.aspx page however is a content page but i do not want to show the left menu bar when the content page is login.

Here's a part of my Master page:

<div id="body">
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />
    <table class="auto-style1">
        <tr>
            <td class="auto-style2" style="vertical-align: top">
                <div id="leftmenu">
                    <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" StaticDisplayLevels="2" Font-Size="Medium">
                        <LevelSubMenuStyles>
                            <asp:SubMenuStyle CssClass="level1" />
                        </LevelSubMenuStyles>
                        <StaticHoverStyle CssClass="hoverstyle" />
                    </asp:Menu>
                </div>
            </td>
            <td>
                <asp:ContentPlaceHolder runat="server" ID="MainContent" />
                <br />
            </td>
        </tr>
    </table>
    <section class="content-wrapper main-content clear-fix">
        &nbsp;
    </section>
</div>

I'm looking for a way to check for the name of the opened page in my MainContent of the Master Page file and if that page is Login.aspx I would set Menu1 to hidden.

You have to think it in the opposite way: access a Master Page's control from Content Page.

This directive causes the content page's Master property to be strongly typed. Add this in you Content Page:

<%@ MasterType virtualpath="~/YourMasterPage.master" %>

Create the following Property inside your Master Page:

public bool IsMenuVisible
{
    get
    {
        return Menu1.Visible;
    }
    set
    {
        Menu1.Visible = value;
    }
}

Use it inside your Content Page:

Master.IsMenuVisible = false;

More information:

Reference ASP.NET Master Page Content

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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