Reputation:
I've inherited some code with a parent master page: content.master. This page has two properties that can be accessed by content pages to control a multi-view server control.
public enum ContentViews
{
vw100 = 0,
vw3070 = 1,
vw7030 = 2
}
public ContentViews CurrentView
{
get { return ((ContentViews)mvwDisplay.ActiveViewIndex); }
set { mvwDisplay.ActiveViewIndex = (int)value; }
}
A direct child content page (content_3070.aspx) can access those properties and set the active view of the multi-view like so:
protected void Page_PreInit(Object sender, System.EventArgs e)
{
((Content_Master)Page.Master).CurrentView = Content_Master.ContentViews.vw3070;
}
I also have content_100.aspx and content_7030.aspx which are direct children and can do the same thing.
That's great. But what I want to do is create another master page: search.master. Seach.master will be a nested master.
<%@ Master Language="C#" MasterPageFile="~/content.master" AutoEventWireup="true"CodeFile="search.master.cs" Inherits="Search_Master" %>
<%@ MasterType virtualpath="~/content.master" %>
From the search.master, I would like to create child content pages (which will be grandchildren to content.master). From these 'grandchildren', I would like to access the content.master properties. But I can't seem to figure out the syntax of how to do this in C#.
Thanks.
Upvotes: 1
Views: 1997
Reputation:
Ok, figured this one out. The solution is to add properties to the child master page (search.master) which can then reference the properties on the parent master page (content.master). Child content pages of the second master (search.master) can then access the properties of their immediate parent master.
So, the second child master, seach.master looks like this:
public partial class Search_Master : System.Web.UI.MasterPage
{
public enum ContentViews
{
vw100 = Content_Master.ContentViews.vw100,
vw3070 = Content_Master.ContentViews.vw3070,
vw7030 = Content_Master.ContentViews.vw7030
}
public ContentViews CurrentView
{
get
{
MultiView mvwDisplay;
mvwDisplay = (MultiView)Master.FindControl("mvwDisplay");
return ((ContentViews)mvwDisplay.ActiveViewIndex);
}
set
{
MultiView mvwDisplay;
mvwDisplay = (MultiView)Master.FindControl("mvwDisplay");
mvwDisplay.ActiveViewIndex = (int)value;
}
}
}
And the multiview on the content.master can be set like this from a content child of search.master:
protected void Page_PreInit(Object sender, System.EventArgs e)
{
((Search_Master)Page.Master).CurrentView = Search_Master.ContentViews.vw100;
}
Upvotes: 1