Click here to Skip to main content
11,582,584 members (71,891 online)
Click here to Skip to main content

Tagged as

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

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

Introduction

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 = 
    (System.Web.UI.HtmlControls.HtmlGenericControl)cp.FindControl("liDepartment"); 
liDepartment.Attributes.Add("class", "active");

To access the li of MasterPageA, the code is:

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

License

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

Share

About the Author

www-sahilv
Software Developer (Junior)
India India
No Biography provided

You may also be interested in...

Comments and Discussions

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