Reputation: 21885
I have two master pages , one is for Desktop and the other is for Mobile , and depends on the device I use dynamically either the Desktop or the Mobile master page. But I can't access the variables from the child ASPX page in the master pages.
The ASPX Code behind :
protected override void OnPreInit(EventArgs e)
{
if (Request.Browser.IsMobileDevice)
{
this.MasterPageFile = "MobileMasterPage.master";
}
else
{
this.MasterPageFile = "MasterPageDesktop.master";
}
}
And in both master pages there are the variables
public int TinyMceWidth { get; set; }
public int TinyMceHeight { get; set; }
But I can't access those two variables from the code behind of the ASPX :
protected void Page_Load(object sender, EventArgs e)
{
Master.TinyMceWidth = 1000; // Can't access
Master.TinyMceHeight = 1000; // Can't access
}
How can I fix it ?
Upvotes: 2
Views: 320
Reputation: 35564
You can acess it like this.
var master = (Site1)Page.Master;
master.TinyMceWidth = 1000;
Site1
is the class name of the Master Page
public partial class Site1 : System.Web.UI.MasterPage
{
}
So because you have 2 masters, you will need to create 2 variables for them
var masterMobile = (Site2)Page.Master;
Upvotes: 1