Referencing custom properties on a Master page from the Child page


We have an optional menu which appears on a few of the pages in a site I’m working on at the moment- this additional menu is on the master page and shown/hidden as needed. We’ve added a public property to the master page’s code behind;

public bool DisplayGrownUpsMenu { get; set; }

On the child pages you can then reference the switch in code like so;

this.Master.DisplayGrownUpsMenu = true;

However, this didn’t initially work- dot net assumed the master page to be of the generic base master page type (System.Web.UI.MasterPage) as opposed to my specific instance of that master page with the extra property (Orchard.Master). As a result, the new DisplayGrownUpsMenu property didnt appear in intellisense and the compiler flagged this as an error. To resolve this you have to add a reference to the specific Master Page type in use, on the aspx side of things by wacking this at the top of the page;

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

Related posts:

  1. No comments yet.
(will not be published)
  1. No trackbacks yet.