views:

114

answers:

2

Hi,

I have a problem with my master pages. They have such inheritance order:

MainMaster1.Master can be nested by Nested1.Master, Nested2.Master, etc. At the same time MainMaster can be duplicated and have working copies like MainMaster2, MainMaster3, etc.

Advise please how can I dynamically change the MasterPageFile of my Nested1, Nested2, etc. pages so that they can easily switch between MainMasters if needed?

I tried to treat the problem in Page_PreInit of the nested masters but couldn't get it entering this event handler. I also tried to change the masters in "protected void OnPreInit" of nested ones but result was the same.

Thanks,

Roman.

+2  A: 

See the following article for several possible techniques you can use:

Dynamically Switching between Master Pages in ASP.NET MVC http://www.codeofrob.com/archive/2009/11/01/dynamically-switching-between-master-pages-in-asp.net-mvc.aspx

Robert Harvey
Thanks but I meant a bit other switching - the switching between Master Pages done in Nested Master Pages - not in the views or pages.
Roman Pavlenko
A: 

I think that's still what he meant, although it doesn't directly answer the question.

Page has a property called MasterPageFile which is used in the above article Page also has a property called MasterPage

On MasterPage, there is a property called MasterPageFile (As in the above article) MasterPage also has a property called MasterPage

While the example on that page covers with changing the master page on the page directly, you can do very much similar to the master page itself by recursing up through the master pages to find and change the one you want.

I hope that helps.

Rob Ashton