ASP.NET: Passing data from content page to master page
14,642
Solution 1
On your master page create a public property - something along the lines of:
public string LabelValue
{
get{ return this.headerLabel.Text;}
set{ this.headerLabel.Text = value;}
}
Then, on your child page you can do this:
((MyMasterPage)this.Master).LabelValue = "SomeValue";
Solution 2
You need to find control by it's id on the content page then set text property of label like this
(Label)MasterPage.FindControl("headerLabel").Text="Your Title";
it better to check null before assigning the text property like this
Label mylbl= (Label) MasterPage.FindControl("headerLabel");
if(mylbl!= null)
{
mylbl.Text = "Your Title";
}
Author by
Phil
Based in the UK, my background is mainly in web development with technologies including Angular, TypeScript and .NET. I am also interested in app development, primarily Android.
Updated on June 14, 2022Comments
-
Phil almost 2 years
I have a label named
headerLabel
in my master page, and I'd like to set its text to the title from the content page. How do I do this?