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.

Thanks

Prashant V.

0
RutuPrash
6/21/2008 6:53:26 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

9 Replies
1013 Views

Similar Articles

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

Your user control shouldn't access the Master page directly, as it will lead to a direct dependency between the two. Instead, use the page as a "broker" between them, so that the page forwards the value from the master page by setting the value in a property on the user control. Let me know if you need code example.


If this post was useful to you, please mark it as answer. Thank you!
0
johram
6/21/2008 7:08:29 AM

Yes Mr.johram,

I didn't get what u stated. pl elaborate it.

a code sample will also do either.

Thank you for quick reply,

Prashant 

0
RutuPrash
6/21/2008 7:32:22 AM

Hi mate,

Try to visit :

http://blogs.ittoolbox.com/c/coding/archives/events-in-master-page-content-pages-16262

http://msdn.microsoft.com/en-us/library/system.web.ui.masterpage(VS.80).aspx


Regards,
Ahmed

***************************************************
Please don't forget to mark the post as Answer, which helps you.

Thank you.
www.ahmadtasnim.com
0
tasnim5
6/21/2008 8:51:48 AM

Hi tasnim,

BTW my problem is how to access master file contents from a user control page that is contained within a default.aspx page which inherits masterpage.

pl feel free to reply if my problem is not self describing.

Thanks

Prashant V 

0
RutuPrash
6/21/2008 9:04:32 AM
Subject
First make the properties in the user control of the value which u want from master page like
 

Property cProductCode() As String

Get

Return lblcProductCode.Text

End Get

Set(ByVal value As String)

lblcProductCode.Text = value

End Set

End Property

then i s urs Default page first fetch the values from master page

like

usercontrolId.cProductCode=Ctype(Master.FindControl("productcode"),TextBox).Text

and the call urs function like

usercontrolId.Initiate_Control()

 

Please mark the answer if u find this post usefull


Always Remember to mark the answer

Samira Mirza
Sr. Software Engineer
Visionaire Technologies
Chandigarh
0
samiradddd
6/21/2008 10:12:28 AM

Hi RutuPrash,

One quick question. do u want to get the text of ur anchor tag at server side?

if yes then u can refer page of UserCntrol using Me.Parent from ascx page.

now u want to fine the Master Page of the aspx page which u can find using

Me.Parent.Master and then u can use findControl Method.

 if u want to access method of Master page which return the list of Text then u can create one public method in Master page and then call it like

DirectCast(Me.Parent.Master, <MasterPageClassName>).<PublicFunction>

Think and enjoy the power of OOP. It will lead to almost all solutions in ASP.NET which u generally not find in any other web language.

Cheers

 


Please mark as Answer if it helps u. Thanks!

Parth Patel
Techsture Technologies
Software Developer
Ahmedabad
0
Coool
6/21/2008 10:57:22 AM

I second samiradddd. Although the example is written in VB.NET. That's the approach I also suggested.

As for Coool's suggestion, it is technically possible although you should be aware that this leads to tightly coupled code - something which may not be a problem if the controls are very tightly related - but something you may want to avoid in most scenarios. Especially when working with user controls, since the OOP concept of reuse is one of the main reasons for building user controls.


If this post was useful to you, please mark it as answer. Thank you!
0
johram
6/21/2008 12:51:44 PM

Sorry, but in my previous post i made a mistake.

U can access Parent page using Me.Parent.Page instead of Me.Parent.


Please mark as Answer if it helps u. Thanks!

Parth Patel
Techsture Technologies
Software Developer
Ahmedabad
0
Coool
6/23/2008 3:04:40 AM

Thank you johram,cool and samir.

I will try this solutions....

Prashant V 

0
RutuPrash
6/24/2008 7:54:00 AM
Reply:

Similar Artilces:

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

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

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

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

Passing Variable from Content Page to Web User Control embedded in a Master Page
Hi there,I have a content page (mypictures.aspx). I have a Master Page with the following code:<%@ Register TagPrefix="ECC" TagName="LeftNav" Src="leftnav.ascx" %>......................... <ECC:LeftNav ID="LeftNav1" Section="Sales" SubSection="" TertiarySection="" runat="server"/>................................  I have the LeftNav - Web User Control (leftnav.ascx). Question:Depending on the content page i am viewing (i.e. mypictures.aspx), I want to change a graphic file in leftnav.ascx file which is embedded or called by the Master Page.I am pretty novi...

Access a DropDownList Selected value in a user control from a content page(nested master page)
 Hi All,I have a DropDownList box in a user control called DDLs.ascx. i have a content page called Sample.aspx which is based on a nested master page. the master pages are called parentMP.master and childMP.master. now i am calling the user control(DDLs.ascx) in the childMP.master like below<%@ Register TagPrefix="ddls" TagName="dropdownboxes" src="~/test/DDLs.ascx" %> now as i said there are 2 Dropdownlist boxes ( ddl1 and ddl2) in this user control.what i want is to access the selected value of these dropdownboxes in the content page and pass them t...

convertion from page to content page or from user control to content page
Hi, I have converted an asp.net 1.1 application to 2.0.  Now what I am looking for some enhancement.  I added a master page and now I want to add other pages as content pages. but those pages which I am converting into content have some user control. Now either I can convert those user control to content pages ( which i want to look for if it is possible),  Or I am thinking i shouldn't convert those user control to content pages cause they might be just good. So looking for some of those people opinion who have worked through this so can I get opinion here please.thanks&nb...

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

Content page accessing master page controls?
I'm probably that much of a noob that I've deviated from the path authors of ASP.NET 2.0 thought of how master and content pages should off been used... Looking from the outside it seemed logical to me that (even on this website) a search text box should be part of a master page and a page that displays results should be a content page... So the problem I'm having (if my hunch about that search textbox control in the header of say even this very website being part of a master page, and result page that subsequently loads underneath the header after you click go bei...

Accessing master page controls from content page
Hello,Here's a snippet from my listing.master page:<%@ master Language="C#" %>     public string Listing_Name    {        get { return lis_name.Text; }    }    protected void Page_Load(object sender, EventArgs e)    {       lis_name.Text = "Hello World"    } ---------------------------------------------------------------------------------------------------------------In my content page, Master.Listing_Name shows blank, why?<...

Master Page , User Control,Content page
 Hi friend ,I have user control at master page, I want to access it's property using content page I have done code but getting problem in deployment.((ASP.usercontrols_travel_hotel_directory_ascx)Master.FindControl("ucHotel_Directory")).Visible = false;  But I am getting following error in deployment project Error    137    The type or namespace name 'usercontrols_travel_animation_ascx' does not exist in the namespace 'ASP' (are you missing an assembly reference?)    d:\By Shakti5385\EternalMewar\Eterna...

Web resources about - How to access Master page file contents in user control page? - asp.net.web-forms

Help:Contents - Wikipedia, the free encyclopedia
Templates are special pages that contain boilerplate text intended to be displayed on more than one page in Wikipedia. This Tip of the day box ...

Portal:Contents/Society and social sciences - Wikipedia, the free encyclopedia
A society is a group of people who form a semi-closed system . At its simplest, the term society refers to a large group of people sharing their ...

Apple debuts new Apple TV ad showcasing tvOS apps & content
Apple today has unveiled a new ad for the fourth-generation Apple TV that highlights the plethora of apps and content available on the new tvOS ...

Scripps Networks Forms Division to Produce Digital, Branded Content
... channel, it has realized that, instead of that utilitarian approach to digital, it might be better off producing more entertaining content like ...

Today’s apps gone free: Content Blocker, The Room, Pry and more
... but trust us, its worth the ride. PRY is available for free for a limited time. It has a 4.5-star rating with a total of 58 ratings. Content ...

Smart Content Center Business Day – ArcticStartup Meets Korean TechHub
... Media to meet the NIPA (National IT Promotion Agency) as well as representatives from the ICT government during the Business Day of Smart Content ...

Apple Needs to Offer Own TV Content after Multiple ‘Speed Bumps,’ Says FBR
FBR & Co. analyst Daniel Ives this morning reflects on reports by Bloomberg and others that Apple ( AAPL ) has shelved an effort to create a ...

Best Holiday Gift for Your Favorite Blogger or Content Creator? A #BlogHer Conference Pass!
Do you love to blog, post status updates, pin, Instagram, tweet, tumble or stumble? Do you love a blogger or content creator? Well, we have the ...

The Content Coattails of the Digital Generation and 5 Ideas To Do Better
... up in the world for people to learn from, react to, discuss or comment on. It seems like each day, we lose a little piece of the soul of content, ...

Michael Eisner on how to make a billion dollars on content, and why this is the 'golden age of television' ...
... Today, with his privately held Tornante Company, he's fully immersed in new media, and has a lot to say about what makes quality content and ...

Resources last updated: 12/13/2015 5:36:43 PM