Phill Healey
Phill Healey

Reputation: 3180

Find Control In Nested MasterPages

I have a control in a nested masterPage, that I need to get at in the codebehind. Ive tried various things and havent been able to get a successful result.

The control is a panel called:

pnlNewsHeader

And this renders on the page as:

MainContent_MainContent_ContentBottom_pnlNewsHeader

These additional names relate to the names of the ContentPlaceholders used across the nested masterPages.

Here is the structure of the page/masterPages, start from page level up to the final masterPage:

 1. BlogPost.aspx
 2. Blogs.master
 3. WebFormsContentCustomBreadcrumbs.master
 4. WebForms.master
 5. Default.master

So how the heck do I grab pnlNewsHeader which is located in Blogs.master from the BlogPost.aspx ???

P.s. The additional names prepending the pnlNewsHeader are the names of the ContentPlaceHolders it resides in as a result of the nested masterPages.

Upvotes: 0

Views: 208

Answers (2)

Ali Umair
Ali Umair

Reputation: 1424

add this markup to the top of you page and access your masterpage in code behind. Update the address of you master pages.

<%@ MasterType VirtualPath="~/MasterPages/Main.master" %>

Upvotes: 0

Edwin
Edwin

Reputation: 1468

You can get a reference to the master page by calling me.Master:

Dim blogsMaster as Blogs = CType(me.Master, Blogs)

or in C#:

Blogs blogsMaster = (Blogs)this.Master;

Then you can just use blogsMaster as you would the page's class (me).

Upvotes: 1

Related Questions