Question

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?

Was it helpful?

Solution

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";

OTHER TIPS

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";
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top