Nested Master Pages and Page controls


I am having difficulties trying to find a control which exists on a page which uses a mater page (nested) but is declared on one of the master pages. To make it easier to understand here's how my code is set up.

I have two master pages:

  1. MasterBase
  2. MasterPage

The MasterPage has a Content control which plugs straight into MasterBase's ContentPlaceHolder. The MasterPage's Content control contains ContentPlaceHolder so that ASPX pages that inherit this MasterPage can plug their Content(s) into those ContentPlaceHolders.

Home.aspx, which I have created uses the MasterPage - and in Content control of the Home.aspx file I have a couple of controls like Label (let's say ID="lblContent1") or Buttons and etc.

What I need to be able to do is, from MasterBase, detect if the page (being rendered) contains certain controls. So for example, in MasterBase's codebehind, I want to look for a control called "lblContent1" and if it does exist, I want to populate it with some data.

Right now, I haven't been successful at doing this. How can I achieve this?


Thanks Yes

5/19/2007 2:37:05 PM 13714 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 4

Something along the lines of:

Label l = null;

l = this.ContentPlaceHolder1.FindControl("Label1") as Label;

if (l != null) {

l.Text = DateTime.Now.ToShortDateString();


should do it. 'this' being the root master page. If you have more complex nesting, then you may have to get a reference to the content placeholder which contains the nested master first (and extract a reference to the master), but once you have the reference to the correct master, the same approach should work.



5/19/2007 11:39:35 PM


The label of the content  page is a protected menber, so you shoud define a public member in the content page and expose the Hidden Field.


if  Still use the FindControl function. For the label in the Content page, its structure can be like the following:



hope it helps.

Amanda Wang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
5/23/2007 4:44:31 AM

Similar Artilces:

Content controls have to be top-level controls in a content page or a nested master page that references a master page.
Why in the world am I getting this error? The solutions I have seen either don't apply or don't work.  Here is my master page code:<%@ Master Language="C#" AutoEventWireup="false" CodeFile="TechLMSMasters/MainSide.master.cs" Inherits="MainSide" %> <%@ Register TagPrefix="usercontrol" TagName="Search" Src="~/library/uc/Search.ascx" %> <%@ Register TagPrefix="usercontrol" TagName="UserName" Src="~/library/uc/UserNameDisplay.ascx" %><!DOCTYPE html PUBLI...

Error : Content controls have to be top-level controls in a content page or a nested master page that references a master page.
when I make a directory on my root, and in that directory I put a masterpage and a web form ... I get always an error : Content controls have to be top-level controls in a content page or a nested master page that references a master page.   Does somebody know what the problem is ? Is it possible you can't set a masterpage in a directory ... ?Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) i've founded ... I had to nest my masterpage ...Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) Hi Joeri Pansaerts, I am receiving the same error as the one posted her...

ERROR Content controls have to be top-level controls in a content page or a nested master page that references a master page.
This all used to work until about 5 minutes ago. Did I change something? For some reason I am now getting this error: Content controls have to be top-level controls in a content page or a nested master page that references a master page. What I have:  I have a masterpage inside of a directory. That directory is a first level directory with its own web.config file....The whole thing is protected by the web.config file above it (in the main public directory). That main public directory has a masterpage as well. I am not currently linking the two masterpages together becuase...

Control of the page and the controls on a page
I am building a web app that has some pages that are public and some that are only available based on subscription. Could someone explain the best way (infrastructure wise) how to control whether a server control is visible or enabledand how to control whether a page is viewable or not based on the user and whether or not the user is logged in (or not). If a user is not logged in I would like some controls to be visible but disabled. I also have to control the URL's in case a person learnsthe URL and tries to type it in. My question is more towards how to do this database wise. I am u...

Using controls from pages, master pages, and user controls
How would I structure my site in this scenario: I'd like to use a dropdownlist all over my site, sometimes in a regular page, sometimes in a master page, and sometimes in a user control.  I wish to bind its events programmatically, so normally I would just put that in the codebehind.  However, I notice a lot of code duplication because I have to declare the control in everywhere, in my base page (which all my pages inherit from), in my base master page (which all my master pages inherit from) and in my base user control (which all my user controls inherit from).How should I be...

i have 3 pages student information , i filled two pages ,then go to 3rd page . First Two pages iam having 100 to store that controls and how to send these controls into 3rd page in ?
i have 3 pages student information , i filled two pages ,then go to 3rd page . First Two pages iam having 100 to store that controls and how to send these controls into 3rd page in ?  There are a number of ways storing values. Check out: Thanks,Karan~ Remember To Mark The Post(s) That Helped You As The ANSWER ~ Hi, Welcome to forums. Now as far as your requirements goes, the first thing that strikes me is that 100 controls are way too many to kee...

cant track down control nested controls/master page
ok i have a master page with a 3 content sections, a aspx page which uses said master, and has inside of the 3rd content sections a ascx controlMaster- <content1/> <content2/><content3/>         PAGE .aspx<content1><LABEL>--i need this value<content1/>            <content3>               <ASCX Control>--in the code behind here        &nbs...

How to Refresh DataList Control in Master page from Nested page
Hi, I have a DataList control in a MasterPage that lists the contents of a shopping basket. The nested pages add products via a Class in App_Code that updates a DataTable stored in session state. My problem is binding the DataTable back to the DataList after updating. I've tried adding a Sub in the MasterPage and calling the Sub Master.SubName but intellidense doesn't show the Sub. Also Master.FindControl("DL_basket") doesn't work. Any advice would be greatly appreciated. Try adding the following to your child page: <%@ MasterType VirtualPath="~/yourMasterPage.master" %> ...

Problem Accessing Page Controls in a page that has a master page.
Hi,  I have a problem with accessing the controls of a page that has a masterpage. I am trying to access the Page.Controls from the code behind in the class file but no controls are returned.I can access single controls (ex. txtAddress.Text) but not the whole array of controls (ex. Page.Controls).  The controls structure is..                                 MasterPage  >  PlaceHolder > MyPage.aspx &n...

How to do post back in a dynamically created user control [provided that update panel is in the master page of the page where user control is added] {B/C of FileUpload Control}
I have a register my scriptmanager and place the update panel around contenttempalte for my pages int the master page. Now in one of my pages i am adding some user controls dynamically. In two of my user user controls I have FileUpload control which will not work under partial post back. So I want's full postback for them How could I do that {Provided that i am on the user control,which is inside the page ,and page have the contenttemplat...

HELP..... Master Page Error (The page has controls that require a Master Page, but none is specified.)
Hi, I had almost finished creting my master page to use as a template for all future internal applications.  I had created a template to use in creatign new applications and had sucessfully created a new project based upon the MasterPage template... All was working well when I noticed a small graphic inconsistancy on the MasterPage... I reopened the MasterPage and I got teh above error message... I have looked at the HTML and everything seems to be okay and there including the header lines... <%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits=&qu...

Calling a method from a control page on the axpx page where the control page exists.
Hello,  I have an .aspx page that has a method called grdMain_DataBind().  I have a control page that loads within the aspx page which has its own logic.  I have a button on my control page called "SAVE".  How can I call the method grdMain_DataBind thats in my aspx logic from the control that exists on that page when I click SAVE button.  Is there a way? If I were you, I'd simply create a "Save" Event within your control. When the Button in your control is pressed, in the Click handler for that Button you can raise the event. Then, within t...

Master Control
I find Master Page idea brilliante. But wouldn't it be nice to have an ability to assign master layout for user controls? Does anyone know of something like that? Look into Themes and Skins. Skins are user to set a template for a contol.Themes and SkinsThemes and Skins 2 Hmm Sean, themes and skins will only help with STYLING the components not layout. What I need is something to set the LAYOUT of the user control and use that master layout to place components in. Like in master page but in user controls.Simple example: Master Control fileUsercontrol layout st...

Obtain instance of Main.master from within User Control code behind when user control is referenced from a nested master page
I have a user control that's being referenced from within a nested master page.  I need to FROM WITHING THE USER CONTROL itself (not the other way around, not Master to user control) access a control in the master page because I need to set it's ImageURL.The setup is like this:Main.master (holds a Menu control called Menu1)        Admin.master (inherits Main.master)                   myusercontrol.ascx (is referenced in Admin.master) I cannot figure out how to get an instance to Main.master from within my...

Web resources about - Nested Master Pages and Page controls -

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Home lost after out-of-control grassfire at Edgecombe in central Victoria
One home is lost after a fast-moving grassfire sweeps through Edgecombe in central Victoria..

Apple’s iOS 9.3 preview page hints at possible Control Center toggle to enable Night Shift
... If you head to the iOS 9.3 preview page on Apple Canada’s website , you can see that there’s an option to enable Night Shift from Control Center ...

#TBT: The Time Ad Age Went All-In for Gun Control
"Can there be any doubt anywhere that violence and contempt for law and order are doing their rotten best to tear American society apart? "Can ...

New Night Shift mode in iOS 9.3 could have its own Control Center toggle
In all likelihood, youll be able to toggle the new Night Shift mode in iOS 9.3 right from Control Center. It came from Canada At least thats ...

Simple free app alerts you when a program (or hacker) takes control of your webcam
... can take over your webcam without you knowing about it. That's right, malware, hackers or even government agencies like the NSA can take control ...

Cruz control: take a look at his puppet master
Cruz control by digby If you read nothing else today, read this Bloomberg article about Ted Cruz's top benefactor, the certifiably looney tunes ...

Run on Italy's Third Largest Bank? Capital Controls or Bail-Ins Next? Why Take Chances?
... "brilliant" comeback? Not a single fundamental problem with Italy, the ECB, the euro, or Europe in general has been fixed. Capital Controls ...

AlunaGeorge share "I'm In Control" ft. Popcaan
... last year to preview material off the followup to their 2013 debut Body Music, and now the first single is here. It's called "I'm In Control" ...

A guy made a remote control airplane using the fan from an old wall heater
... and old heater in his house when he realized that the blower motor inside of it could work a lot like a jet engine — so he made a remote control ...

Resources last updated: 1/21/2016 7:11:12 PM