How can I access a control on a master page from a user control using properties?


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 and not run-time).  I therefore tried the following without success.

In my master page I have :

public string FormName
            return lblFormName.Text;
            lblFormName.Text = value;

Within an aspx page I'm able to set values fine using

Master.FormName = "My test form";

This doesn't work in an ascx file however (and I've also tried Page.Master.FormName...)

Any help would be greatly appreciated.

6/1/2007 11:47:00 AM 13714 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 18

 You need to cast the type of the master page before setting it's property, for example:


MyMasterPage master = (MyMaster)Page.Master;
master.FormName = "My test form";
German Afanador
6/1/2007 3:02:44 PM

Hi Trebolin,

Thanks for your response, unfortunately I'm still having difficulty.  My masterpage code-behind is shown below - what code would you suggest using in my user control to get this working?  Many thanks.

namespace myMasterPage
    public partial class EForms : System.Web.UI.MasterPage
        protected void Page_Load(object sender, EventArgs e)


        public string FooterText
                return lblFormName.Text;
                lblFormName.Text = value;

6/4/2007 9:00:32 AM

I've got this working now - I just had to use the name of my master page as the type i.e. my masterpage was called EForms.master so all I needed in my user control was :

EForms xxx = (EForms)Page.Master;
xxx.FooterText =

6/5/2007 8:26:56 AM

Similar Artilces:

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

Accessing a control inside of a User Control within a master page using jscript
To be more precise, I'm using a master page called Main.Master, i have one web form called default.aspx.  It contains nothing. I use user controls to display everything.  For simplicity sake the user control here will be called newproject.ascx. This user control has several text boxes and a save button.  When the save button is clicked, I want to utilize the OnClientClick event and use javascript to validate the values in all the controls before passing them to sql. The source for the button is as follows: <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btn...

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

Unable to access user control's user control's function\property from another user control
Hi, I used to call an user control's user control function as stated below from my user control in ASP.Net 1.1 wucCompany.wucEmployee.GetEmployeeSomething() After migrating to ASP.Net 2.0, I am unable to use any properties/functions(even the public ones) of the user control's User control's from another user control.  The way I have to do is create property\function in wucCompany which calls the wucEmployee's property\function and call the wucDepartment.GetEmployeeSomething().Since I need to do this change in too many places, I can...

Set User Control Properties at run time (for same user control used more than once on the same page)
I have a user control which contains some textboxes and radio buttons. I have created public properties on the user control so that they can be access from the page using the UserControl.I load the user control dynamically into my parent page. I do this 3 times for the same user control, and I set the properties for the user control at run time to populate the radiobutton list and textbox.The problem is that even tough each of the UserControls load, only the first one populates its textboxes/radiobutton lists.p.s I am not using a reader purposefully because there are...

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

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

How to access a user control from another user control in a Wizard control
My page has a wizard control and each step is a user control.  I could find the value of a control in step1 user control in the wizard page but not in step2 user control.From wizard.aspx.vb – it worksDim m_title As DropDownList = CType(Me.PersonalBox1.FindControl("ddlTitle1"), DropDownList) Question:How can I find the value of a control(textbox or dropdownlist)in step1 user control from step2 user control? I want to find “PersonalBox1.FindControl("ddlTitle1")” from Step2 AddressBox1. I have tried several ways to access it but no luck. From AddressBox.ascx.vb –...

values of web controls in user control can not be access from other pages???
I have aspx page(brief code: includes ascx file) <%@ Register Src="reseller.ascx" TagName="reseller" TagPrefix="uc1" %> <form id="form1" runat="server"> <uc1:reseller ID="idreseller" runat="server" /> </form> the code for asxc file . i have the PostBackUrl to reseller.aspx <asp:TextBox ID="txtPostCode" runat="server" CssClass="form1" Width="50" MaxLength="4" /> <asp:ImageButton ID="ibtn"  ImageUrl="images/searchbutton.jpg" PostBackUrl="~/reseller.aspx" runat="server"  /> In my reseller page i try to read the post value of control txt...

How can I access the property a control on a master page from the master page's code behind.
On my master page I have a label. I want to change this label's text property based on an element of the querystring. (label.text = "NewValue")All child pages using this master will display the same thing so I was trying to put the code in the master page so as not to have to duplicate it for the child pages or put it in a base class and use FindControl.Is it possible to access from a master page's codebehind the property of a server control that is placed on a master page's aspx? If so how?(I saw similar questions, but they all came from the view of a child accessing the property.)Thank you...

Accessing properties of user control inside user control
I have a simple MemberPhoto user control which has a photo of a member along with username and if they are online.I would like to reuse this control inside of another user control (MemberSummary) that would include the member's photo and some basic information about the member.  I would like to know what is the "Best Practice" to set/read properties on the member photo control from a web form.1. Should the MemberSummary define a property that returns the MemberPhoto user control and there I would have access to th...

Web resources about - How can I access a control on a master page from a user control using properties? -

General Growth Properties - Wikipedia, the free encyclopedia
Chicago , Illinois , U.S. General Growth Properties, Inc. is an American real estate investment trust , headquartered at 110 North Wacker Drive ...

RentalRoost Brings Facebook Into Process Of Matching Up Home Seekers, Available Properties
... places to live , as RentalRoost , a San Francisco Bay-area-based website that incorporates Facebook data into its rankings of available properties, ...

Extended Profile Properties - Facebook-Entwickler
These Permissions cannot be revoked in the Login Dialog during the login flow, meaning they are non-optional for Users when logging into your ...

PortPerry Properties (@brian14mckinlay) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Hawaii Real Estate Properties for iPad on the App Store on iTunes
Get Hawaii Real Estate Properties for iPad on the App Store. See screenshots and ratings, and read customer reviews.

Australian Federal Police raid properties in new CFMEU-linked investigation
Federal Police have raided properties as part of an investigation into a CFMEU organiser suspected by authorities of being bribed.

Sydney gateway: Rail line to be moved, properties affected under plan to link WestConnex to airport
A key rail line linking Sydney's west with Port Botany will need to be shifted under tentative plans to build separate motorways to Sydney Airport. ...

Digital detox: Australians seek out nature properties to overcome technology burnout
Holiday home rental companies say they have seen a spike in the number of customers seeking digital detoxes, allowing savvy homeowners to offer ...

InvenTrust Properties Corp. Announces Acquisition of Two High Performing Open Air Shopping Centers
InvenTrust Properties Corp. (&ldquo;InvenTrust&rdquo; or &ldquo;the Company&rdquo;) today announced that it has acquired two high performing ...

CoreLogic: "Number of Mortgaged Properties with Negative Equity Down 20.7% Year Over Year"
From CoreLogic: CoreLogic Reports 256,000 US Properties Regained Equity in the Third Quarter of 2015 CoreLogic ... today released a new analysis ...

Resources last updated: 1/13/2016 3:36:36 AM