public class Default : System.Web.UI.Page
{
protected override void OnPreInit(EventArgs e)
{
if (runtimeMasterPageFile != null)
{
this.MasterPageFile = "~SubMaster.master";
}
base.OnPreInit(e);
}
}
Let us say the ContentPlaceHolder in SuperMaster.master is "SuperContent".
If you want to get the refrence of the controls in the SuperMaster.master use the following syntax.
If suppose a TextBox named "TextBox1" is placed in SuperMaster.master then in Default.aspx you can get the reference of the control as follows...
TextBox txt = (TextBox)this.Master.Master.FindControl("TextBox1");
If you have placed a DropDownList named "DropDownList1" in SubMaster.master and to get the reference of the same in Default.aspx you are wrong if you think that the following will work.
DrownDownList ddl = (DrownDownList)this.Master.FindControl("DropDownList1");
The above statement will give runtime error.
The solution for this is you need to get the control reference form the ContentPlaceHolder which is placed in SuperMaster.master as follows...
//To get the ContentPlaceHolder reference placed in SuperMaster.matser
ContentPlaceHolder cntPlh = (ContentPlaceHolder)this.Master.Master.FindControl("SuperContent");
//To get the DropDownList Reference from the SubMaster.master in Default.aspx
DrownDownList ddl = (DrownDownList)cntPlh.FindControl("DropDownList1");
This problem i have faced for two days and finally i got the solution....
Thats all you can enjoy the coding using Nested MasterPages....
PanduKovur