Click here to Skip to main content
13,138,791 members (55,689 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 23 May 2014

How to Access Sub Master Page WebControl and Super Master Page WebControl on Content Page in Nesting of Master Page

, 23 May 2014
Rate this:
Please Sign up or sign in to vote.
Access Web Control on Content Page of Nested Master Page


Sometimes, a scenario arises when we need to control the navigation of a page which is inherit Super Master Page and then Sub Master Page in nesting of Master Page. Then how do we access the Super Master Page web control and Sub Master Pager web control. Here are some tips.

Using the Code

Suppose we have a Master page named A and Master page B and then a Content Page.

Content Page inherits MasterPageB and MasterPageB inherits MasterPageA.

Now there is a navigation bar in MasterPageA and one in MasterPageB.

To access the li of navigation of MasterPageB from ContentPage who directly inherits MasterPageB, the code is:

The li should be runat="Server" and also had an id

ContentPlaceHolder cp = (ContentPlaceHolder)this.Master.Master.FindControl("ContentPlaceHolder1");

        System.Web.UI.HtmlControls.HtmlGenericControl liDepartment = 
liDepartment.Attributes.Add("class", "active");

To access the li of MasterPageA, the code is:

 System.Web.UI.HtmlControls.HtmlGenericControl liDashboard = 
 liDashboard.Attributes.Add("class", "active");
Hope this will work for you...


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Junior)
India India
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 23 May 2014
Article Copyright 2014 by www-sahilv
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid