[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

How do I reference controls in a nested master page from the content page code-behind?

I have a master page and several nested master pages in an ASP.Net 2.0/C# site. I have been able to reference controls in the master page from the various content pages by using the following...

            ((HtmlGenericControl)Master.Master.FindControl("objBody")).Attributes.Add("Class",
            "cssadmin");

Now I have a control in a nested master of the master page that I want to set the class value of a DIV control based upon which content page is currently displayed.

Master Page--->Nested Master Page --> DIV on nested master page  needs to be referenced from a content page that uses the nested master page (Master-->Nested Master-->Content page).

I tried the following code in the content code-behind with no luck.

            ((HtmlGenericControl)Master.AdminNestedMaster.Master.FindControl("objDivMenu")).Attributes.Add("Class",
            "Admin-AccessLevels");


and...

            ((HtmlGenericControl)AdminNestedMaster.Master.FindControl("objDivMenu")).Attributes.Add("Class",
            "Admin-AccessLevels");


Does anyone know how to reference the DIV control in the nested master?
0
dcadler
Asked:
dcadler
1 Solution
 
bedanandCommented:
You can find the control on nester master page is like this.

HtmlGenericControl div = (HtmlGenericControl)this.Master.Master.FindControl("ContentPlaceHolder1").FindControl("objBody");
        div.Attributes.Add("Class", "cssadmin");

Where  ContentPlaceHolder1 is the id of the content place holder of main master page.

Note: Must have the runat ="server" for div on nested master page.

0
 
dcadlerAuthor Commented:
Thanks. This worked exactly as I had hoped.Good job!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now