Accessing Master Page Controls from Page

How can a page access its master page controls?

Suppose a page's (.aspx) master file (.master) contains a control (e.g., Label myLabel).  How can one access the master file's control(s) within the scope of the page?  The this.Master.Controls collection (where this is the page in question) does not return what one would most likely think it would return.

0
Informatosaurus
3/27/2009 3:28:14 AM
asp.net.navigation-controls 13714 articles. 0 followers. Follow

6 Replies
985 Views

Similar Articles

[PageSpeed] 26

ContentPlaceHolder mpContentPlaceHolder;

TextBox mpTextbox  = new TextBox();

mpContentPlaceHolder = (ContentPlaceHolder)Page.Master.FindControl("ContentPlaceHolder1");if (mpContentPlaceHolder != null)

{

mpTextbox = (Textbox)mpContentPlaceHolder.FindControl(txtName.Text);

}

refer below links for more examples

http://www.codeproject.com/KB/aspnet/InsideMasterPages.aspx

http://aspnetlibrary.com/articledetails.aspx?article=Access-Master-Page-controls-from-the-Content-Page

 

 


Please mark it as answer if it resolves the issue.

visit: http://technicalsol.blogspot.com
0
sumitd
3/27/2009 3:51:39 AM

Hi, everybody!

I was able to resolve my problem.  Here's what I did...

First, I exposed the control in the master file via a public read-only property:

public <ControlType> <PropertyName> { get { return this.<controlVariable>; } }

Then, I accessed the property in the page:

<ControlType> <controlVariable> = ((<MasterPageType>)(this.Master)).<PropertyName>;

That was easy!

Note: The <placeholders> are placeholders.  The angle brackets are not part of the syntax.

Feel free to contact me should you have any questions.

Thank-you to all who responded.

0
Informatosaurus
3/27/2009 2:35:41 PM

Hi Informatosaurus,

Please mark the post which has helped to reach the solution or you can mark your solution only answer, it will help others to know the solution of the problem.


Please mark it as answer if it resolves the issue.

visit: http://technicalsol.blogspot.com
0
sumitd
3/27/2009 5:10:32 PM
MasterPage d = this.Master as MasterPage; 

d.Testing();

d.FindControl("");

 


Thanks
Hari
---------------------------------------------
Dont forget to click "Mark as Answer" on the post that helped you.

My Site
0
hariram
3/27/2009 5:35:49 PM

<%@ Reference Control="~/Bar.master"%>

if (this.Page.Master is Bar)
{
Bar barMasterPage = (Bar)this.Page.Master;
barMasterPage.ProcessBarLabel(message);
}


Thanks
Hari
---------------------------------------------
Dont forget to click "Mark as Answer" on the post that helped you.

My Site
0
hariram
3/27/2009 5:39:45 PM
Reply:

Similar Artilces:

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

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

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

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"),...

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 controls.how 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 controls.how to store that controls and how to send these controls into 3rd page in ?  There are a number of ways storing values. Check out: http://msdn2.microsoft.com/en-us/library/75x4ha6s.aspxhttp://www.csharphelp.com/archives/archive207.html Thanks,Karan~ Remember To Mark The Post(s) That Helped You As The ANSWER ~ Hi, Welcome to asp.net forums. Now as far as your requirements goes, the first thing that strikes me is that 100 controls are way too many to kee...

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? E.g. Master page :- .... <asp:placeholder id="BreadCrumbs" runat="server" /> ..... In my default.aspx page I have :- ..... <asp:contentwebpart id...

Access Content Page Control from Master Page
I use Master page in my application. i want to access the content page control (Text Box)  from master page and change the control (Text Box) value. i cant find the text box by using Findcontrol also Let’s turn to the FindControl documentation on MSDN. FindControl searches the current naming container for the specified server control. Master.FindControl("ContentPageHolder1").FindControl(TextBox) Reading this nice article.http://odetocode.com/Articles/450.aspx   MPI never desire to converse with a man who has written more than he hasread. -Samuel Johnson, lexic...

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

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

Accessing Content Page Control From Master Page
I'd like to access the value of a control residing on a content page from the associated master page. Can anyone point me in the right direction?   Thanks When you know the classname of your page, use: (in VB.NET) CType(Page, classname).ControlID.propertyName But this code will go wrong on all the other pages, so you have to check on which page you are. This being said, I advise you to consider another approach.Your master page should not use code that depends on the design of a particular content page. Your content pages should depend on your master page, not the other ...

Accessing Master page control from child page
Hi, In my application I have implemented a customized error control, which gets visible on any error raised. Issue is, in one of the page where we have implemnted Update Panel, and onClick of a button I wants to raise a error on the control in Master page. The Page object has a Master property that will reference the properties of the master page.  Note that you will need to apply the MasterType directive to your page or use the Page.MasterPageFile property to reference the master page properties.Christopher Reed"The oxen are slow, but the earth is patient." hi, Y...

Web resources about - Accessing Master Page Controls from Page - asp.net.navigation-controls

Highest Percentage Of Opera Mini Users Accessing Facebook? Macau
If you were asked to guess which country had the highest percentage of users of Opera mobile Web browser Opera Mini users accessing Facebook ...

International Users Accessing Facebook Places Through US VPN Accounts
By using a virtual private network (VPN) hosted in the United States, Facebook users from around the world are accessing Facebook Places. The ...

What are some alternatives to Yodlee for accessing bank information?
Clay Loveless , Founder, Jexy. Co-founder, Mashery. Founder, Jexy. Co-founder, Mashery.

Cloud Console - Accessing files in cloud storage for iPad on the iTunes App Store
Get Cloud Console - Accessing files in cloud storage on the App Store. See screenshots and ratings, and read customer reviews.

Meryl Streep On Accessing The Characters Within - YouTube
Meryl Streep talks about the importance of an actors work representing their ability. CONNECT WITH AFI: http://facebook.com/AmericanFilmInstitute ...

Accessing the Future Fund a sensible proposal, says super expert Daryl Dixon
As portfolios go, the Future Fund's asset allocation is concentrated in higher-risk investment, including equities and alternative assets.

Accessing my Super
I'm 57 - can I access my super?

Australia, US accessing Indonesian telephone data, leaked documents show
Newly disclosed documents from former US intelligence contractor Edward Snowden have revealed that Australian intelligence efforts against Indonesia ...

Euthanasia advocate Philip Nitschke detained at Melbourne Airport, accuses Customs officials of accessing ...
Euthanasia advocate Philip Nitschke has accused Customs officials of accessing hundreds of patients' sensitive records on his laptop after detaining ...

Frances Abbott scholarship: Sydney woman pleads guilty to accessing Whitehouse Institute records on PM's ...
A Sydney woman who leaked the student records of Tony Abbott's daughter pleads guilty. A Sydney woman who leaked the student records of Prime ...

Resources last updated: 1/21/2016 6:35:54 PM