質問

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?

役に立ちましたか?

解決

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

他のヒント

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";
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top