How to change MasterPageFile programmatically

I have a main page and this main page has the following code

<%@ Master Language="C#" AutoEventWireup="true" MasterPageFile="../sales/sales.master" %> <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server"> </asp:Content> 

Now here is the problem that I have ... it's a copy of the other main page of the site, but I have several sites that will use it, and I just want to make it common for everyone, but I still want to get access. " sales / sales.master "the problem is that it is inside each site folder, for example

 Web/ mySite1 sales sales.master mySite2 sales sales.master 

But now I need to have a master who will do the same for everyone

 Web/ All mynewmaster.master mySite1 sales sales.master mySite2 sales sales.master 

so in mynewmaster.master I want to call MasterPageFile = "../sales/sales/master", but I can’t because 1) he won’t find it and 2) he won’t know what to look at ..

Sales.master has all the CSS everything I need .. + other things that I will add ..

+4
source share
1 answer

I believe that you can change the wizard only with OnPreInit :

 protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); Page.MasterPageFile = "MasterPage.master"; } 
+10
source

All Articles