0

如果我想将常规母版页用于新的页面布局,但我不希望主导航菜单控件(第 3 方控件)可见,如何让页面布局隐藏它?在 asp.net 中,我会在母版页上公开一个公共属性或方法,然后从子页调用它,但不确定在 SharePoint 中可以做什么,因为没有代码后面或可识别的母版页类。

4

1 回答 1

0

I got it working like this but I'm not in love with the implementation.

On Master Page:

...
            <c:Menu id="myMenu" runat="server" />
            ...
        </form>
    </body>
</html>

<script runat="server">
    public bool IsConsumerNavVisible
    {
        set
        {
            myMenu.Visible = value;
        }
    }
</script>

On PageLayout:

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Reflection.PropertyInfo pi = Page.Master.GetType().GetProperty("IsConsumerNavVisible");
        pi.SetValue(Page.Master, false, null);
    }
</script>

So I exposed a public property on the master page to set the visibility and then used reflection on the PageLayout to find & set that property. I tried putting the PageLayout code in just a <% %> script block and it executed but the menu would end up visible anyway. Putting it in a Page_Load event handler fixed that. If there is a better way I'm all ears.

于 2013-03-07T20:29:23.633 回答