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

The above works fine. I cant seem to find a similar way to reference the master page directly from the user control though. Any help will be appreciated. Thanks!

Cheers

Jim


Jim
0
jthomas
3/23/2007 12:17:20 AM
asp.net.navigation-controls 13714 articles. 0 followers. Follow

3 Replies
1806 Views

Similar Articles

[PageSpeed] 57
Get it on Google Play
Get it on Apple App Store

from within a usercontrol, you should be able to do it like this:

Dim mpLabel As Label 
mpLabel = DirectCast(Me.Page.Master.FindControl("LabelStatusMsg"), Label)
 
Mike Banavige
~~~~~~~~~~~~
Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
3/23/2007 12:53:44 AM

Hello Mike,

That worked like a charm. Thanks!

Cheers

Jim


Jim
0
jthomas
3/23/2007 5:10:33 AM

Mike,

 a c# version? with a dropdownlist instead of a Label as well.

 thanks.

0
info
4/15/2008 2:00:44 AM
Reply:

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

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

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

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

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 user control defined in master page from any content pages
I have a user control named header.ascx in a master page.  This user control contains a labels which states "You have logged in as Guest ". Now i have a home page, named home.aspx which contains a login.ascx user control.  Now whenever somebody provides the correct logon details i would like the status in the main masterpage user control to be changed to "You have logged in as ___" (name of the user).NB: In order to facilitate this i would be able to access the master page user control label field.  How do i do that?Steps already tried are as follows: ...

accessing user control peroperty ...from the content page(Master page)
I have written a property in the .ascx page, I want to set this property from the content page...I use the following code..System.Web.UI.UserControl csd = (UserControl)this.Master.FindControl("BreadCrump1");        string s = csd.ToString(); I am getting the control name and the property name in the "csd" object, My question is how to access set the value of the property from the csd object Any help will be appreciated.. Thanks in advanceRaj  ...

How to access Master page file contents in user control page?
Hi Friends,My problem scenario:I have a masterpage. In that I have 5 <a ...>Show Text</a> parts ok.I have created a default.aspx. I referenced the masterpage in it.I have now products.ascx user control file.This will be shown in Default's contentpage holder right.Now i want to access masterpage file's anchors along with its text in products.ascx . How can i achieve it? or is there any workaorund for it? pl fell free if my problem dowsn't elaborate itself.ThanksPrashant V. Your user control shouldn't access the Master page directly, as it will lead to a direct d...

Access value of a user control from Master Page in content page
 Dear Experts,Please help me on this issue. I have a master page which is composed of user controls like header, footer, left menu and content place holder. Now I want to access a value from header in the content place holder page. How to achieve this? Regards salah You first need to expose the value from the header as a public property and then you'll need to expose that (or the user control) as a public property of the master page. Here's an article about exposing properties on a master page - http://www.codeproject.com/KB/aspnet/InsideMasterPages.aspx; you use the...

Problem to use TreeView Control in a 'content page' This Error Occur "Only Content controls are allowed directly in a content page that contains Content controls."
hi I am trying to use the TreeView Control inside the content page (Page that has a master page is a content page). On compiling the project I got the following ASP.Net runtime error: "Only Content controls are allowed directly in a content page that contains Content controls."B@b@R J Issue resolved. I was putting script tag in the content page that is not allowed. when remove the script from content page problem is resolved.B@b@R J...

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 www.hopeasp.net 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...

Web resources about - Need to access a Label Control on the Master Page from a user control attached to a content page - asp.net.navigation-controls

Serial attached SCSI - Wikipedia, the free encyclopedia
3.0 Gbit/s at introduction, 6.0 Gbit/s available February 2009, 12.0 Gbit/s in development Serial Attached SCSI ( SAS ) is a communication protocol ...

Facebook + Twitter + Klout + Pinterest = No-Strings-Attached Dates? April Fool’s!
... and Klout, and then brings it into Pinterest and uses a “secret algorithm” to match up “like-minded Pinterest users” for “no-strings attached ...

Facebook proposes changes to privacy policy, affecting how users’ likenesses are attached to ads
... of rights and responsibilities, Facebook notes that users can tweak their privacy settings to decide if they want their likeness to be attached ...

Nsync-no strings attached HBO - YouTube
este es el comienzo del concierto,a diferencia del anterior este esta "SUBTITULADO..."

Cat goes sky high attached to glider
Two people flying an open-cockpit glider in French Guiana forgot to check their aircraft for additional passengers, leading to a bizarre surprise. ...

Home help has strings attached
Home help has strings attached

Human Nature delivers festive cheer with strings attached
Human Nature and the MSO Hamer Hall, December 22 & 23 &#9733;&#9733;&#9733;&#9734;

New face grown from Xu Jianmei's breast attached in Fuzhow, China
A TEENAGE girl who suffered horrendous burns has been given a new face grown from one of her breasts.

Shows not to get attached to: About a Boy, Battle Creek, Constantine, Cristela, Backstrom
&#160;You know how it is - you're just getting to know each other. You like what you see and you're thinking of moving the relationship up a ...

Andy Coulson released from prison with electronic tag attached
London: Former News of the World editor and Downing Street spin doctor Andy Coulson has been released from prison.

Resources last updated: 12/17/2015 7:08:31 PM