Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
already tried this code nothing doing plz help:-

this.Master.FindControl("lblMyLabelName") = this.defulatpageLabel;

i want lets say to copy labels text from defualt to another labels text in master page
Posted
Updated 16-Jun-11 14:50pm
v4
Comments
[no name] 16-Jun-11 16:09pm    
And what is happening? Exceptions, errors, null? You need to slow down and fully explain.

Hi One way you can retrive it by this way
First in your master page code behind try to create a property that exposes this control you are going to access.
C#
public String LabelValue
{
        get { return lblinMaster.Text; }
}

Then in your content page (ASPX) add a reference to master.
<%@ MasterType VirtualPath="~/MasterPage.master" %>

You are done and you can access Master.LabelValue in content page code behind.

Ofcourse if you are trying to control everything, try to create a base page and keep the fields you want to control here, inherit all your pages from it.

Thanks,
Debata
 
Share this answer
 
v2
Comments
RakeshMeena 17-Jun-11 0:43am    
My 5! Agree with you as I think this is a better way to access Master page controls.
You can get to the master page from the aspx page , and to the aspx page from the master page. I don't recall how right off hand, but I now it's easy to find if you use google.

2.75 MILLION google results for "access aspx page from master page"[^]
 
Share this answer
 
Comments
Abdullatif M. Abu Al Rub 17-Jun-11 0:59am    
what the helll is wrong with you?
you aint answer nothing! you allways provide a "google search results link"
you should just keep it to your self
do you really think that people don't use google before coming here

people are not the same mind may some them find google not useful!
just post an answer or do nothing
C#
Label masterLabel = (Label)this.Master.FindControl("lblMyLabelName");
 
Share this answer
 
You can follow the bellow code:
C#
((Label)Page.Master.FindControl("lblMyLabelName")).Text = "Hello";

Thanks,
Mamun
 
Share this answer
 
Don't ask for fast help. It's not our fault you're taking on jobs you're incapable of.

You CAN use the find control stuff, but I prefer to do things more cleanly. I derive all my pages from a base page that I use to add functionality for all my pages. Then in that I will override the Master property, and have it return a strongly typed instance of my actual master page class, instead of the base class. You could always just upcast the Master property, but my way is cleaner.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900