How to access master page controls from .ascx controls?

I have a site where a master page is defined with a placeholder control in it.

In the content page I have am accessing various ascx controls from within webpanels (each panel loads an associated ascx file).
In one of the ascx files, I want to programmatically change the content of the placeholder that I put on the master page. How do you access this?
Master page :-

<asp:placeholder id="BreadCrumbs" runat="server" />

In my default.aspx page I have :-

<asp:contentwebpart id="pBlogs" runat="server" title="My Blog" scrollbars="vertical">
<datanet:BlogPart runat="server" />

With the dataNet:BlogPart pointing to an ascx file.
The ascx file is not inheriting from master in any way at the moment as it's being placed within the default.aspx page which does. So in a way it will indirectly inherit from master.
Within this ascx file I want to reference BreadCrumbs from the master page.
How do you do this?
3/4/2004 9:33:52 PM 13714 articles. 0 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 59

You need to find the breadcrumb control and then use it - something as follows (following code looks up a label l1 on the master from the content page) 
 foreach (Control c1 in this.Controls) {

if (c1.FindControl("l1") != null)
((Label)c1.FindControl("l1")).Text += " posted";
Hope that helps,
3/5/2004 5:50:03 AM
You could probably use Master.FindControl(...)

/Fredrik Normén - fredrikn @ twitter

Microsoft MVP, MCSD, MCAD, MCT

My Blog
3/26/2004 9:28:40 PM

Fredrik, I don't like that route, you then have to fiddle with it at runtime as opposed to just using intellisense and grabbing a reference to the master page at compile time (if this makes any sense).  For instance I have the same problem.  I want to say MyMaster.SomeControl.Whatever where SomeControl is a control in MyMaster that I esposed through a public property.  That seems a bit easier to me so how would you reference a master page like that from within one of the master page's referenced user control's code behind?

When is Microsoft going to get rid of VB.NET!
8/25/2008 4:49:14 AM
 //sample code in user control which would be placed in the master page

If TypeOf Me.Page.Master Is AdminMaster Then

Dim adminMasterPage As AdminMaster =     

DirectCast(Me.Page.Master, AdminMaster)

adminMasterPage.HeaderLabelText =”sample text”             

End If

Please remember to click “Mark as Answer” on the post that helps you and actually answer your question.
5/4/2009 12:00:31 PM

Similar Artilces:

How to access page control (editor control) from user control?
Hi, I want to do something, but I don't know if it's even possible. I'm trying to make a simple application to edit my website. I have a page called editPage.aspx which contains an editor control. (cuteEditor from cutesoft) I also have a Treeview that dynamically populates my website structure. I placed this treeview in a custom control (populateTreeView.ascx) and placed it on the editPage.aspx page. When you click on a html file in the treeview (inside the custom control) I check if the file exists. If it does exists I send it to a class which retrieves the editable region within this ...

How to access a master page control in a user control.
Hi All, I need to access a scriptmanager control placed in a Master page. The scriptmanager is used to RegisterClientScript in the Custom User Control.  The UserControl is placed in a child web page of the Master page. How do I do this? Thanks in advance, Rohan.      There's a ScriptManagerProxy control you can use for this; just drop it onto the user control and you can use that instead....

access controls in user control on a master page
Have a simple question.. I have a dropdown list in a user control within a master page.When I change selection in ddl, I want to access value on the content page.For that, right now I need to refresh the page.. don't know why.. one way around this cud be to declare a public property for UserControl and access it, but I can ONLY see this UserControl in MasterPage... not in a content pageWhile rendering, first content page loads, then MasterPage.. so I can not access changed/current value in the dropdown.. Can someone help?-------------------------------------------------Click on &...

Need to access a Label Control on the Master Page from a user control attached to a content page
Hello all, I have a master page (say  site.master)  with a status Label in it. I have a content page ( say content.aspx)  that has a user control (say usercontrol.ascx). One of the Button Click Events in the usercontrol.ascx needs to pass on some text onto the status label on the masterpage(LabelStatusMsg) and display it. I have been able to do this directly off a content page (content.aspx) by using the following code (VB)  on the master page <%@ MasterType virtualpath="~/site.master" %> and Dim mpLabel As Label = CType(Master.FindControl("LabelStatusMsg"),...

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...

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...

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...

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...

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...

How can I access a control on a master page from a user control using properties?
Hi, I have a master page which I'm using on my aspx page.  Within this aspx page is a user control and I would like to set a label on my master page using a value from my user control. I can do this using FindControl as shown below but I would like to use properties in my master page. The following code in my user control works perfectly: Label theFormName = (Label)this.Page.Master.FindControl("lblFormName");theFormName.Text = "My Test Form"; However I've been told that using properties is a much better ideas (errors would be picked up at compile time an...

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...

page access control in custom control?
 hi,I'm planning to building a custom control, to be used with membership/roles, so on the page it will look something like this:<abc:MyControl>   <Admin>   ....   </Admin>  <Developer>...</Developer>  <QA>...</QA></abc:MyControl> so that each section will be shown just to the roles assigned to the user.  now the question is say i drop a dataGrid into one of them, how do i access it?  I don't want to do it at the control level, as the control can be used elsewhere and not have a dat...

Accessing controls on user control page
I have a main page that interfaces with a web service and returns a dataset.  I also have a user control page that contains a datagrid.  I have the user control registered and displaying on the main page.  However, I don't know how to gain access to the datagrid on the user control from the code on the main page.  There doesn't seem to be a way to directly assign values to the properties of the datagrid like you could if it were on the main page itself.  I can't seem to just do:GridView1.DataSource = Contact; GridView1.DataBind();  because I can...

Web resources about - How to access master page controls from .ascx 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 ...

Grand Mufti of Australia in damage control after Paris attacks
AUSTRALIA’S top Muslim cleric has gone into damage control.

69 percent of users would bypass security controls to win a big deal
When faced with the chance of clinching a major deal people are willing to throw security controls out of the window. This is according to research ...

Obama to Veto Bill Requiring Background Checks On Syrian Refugees; France Demands Tighter Controls, EU ...
... does not call for ending the refugee program or require religious screenings, as some Republicans have demanded . France Demands Tighter Controls, ...

2 Killed After Helicopter Spins Out Of Control, Bursts Into Flames At Southern California Airport
Two people on board a helicopter were killed when the aircraft spun out of control after landing and burst into flames in Carlsbad.

‘The Gun Control Song’ Channels Billy Joel To Troll Libs … Is Internet Gold
‘The Gun Control Song’ Channels Billy Joel To Troll Libs … Is Internet Gold

This App Lets You Control Your Smartphone By Drawing
Mouse gestures never made sense on PCs, but they're awesome on Android. Long before we started swiping and tapping on touch screens, mouse gestures ...

Mom And Dad Are Watching: 80% Of Parents Say It's OK To Secretly Put Control Apps On Kids' Phones
The biggest social media risks according to parents: Facebook and Snapchat. Men are more likely than women to trust children online.

Obama: I’m thinking I’ll spend my last year in office focused on gun control
Plans. Your alternate headline comes from Charles Cooke: “President Obama announces record gun sales in 2016.” So two of his major priorities ...

Resources last updated: 11/21/2015 1:39:40 AM