tags:

views:

348

answers:

4

I have a label in a master page (sample.master) called lblHeading.

I want to dynamically change the text of the label when I load the content page.

I need to do this because I want to change the heading to something meaningful but only after I know about the content of the page.

Is this possible?

+3  A: 

Yes.

You want to create a strongly-type master page and you can then access it's properties from your content page during Page_Load or wherever else.

James D
+1  A: 

You can create a public property in the masterpage that will change the label.

public string Heading
{
    set 
    {
        lblHeading.text = value;
    }

}
CD
+1  A: 

Yes, it is possible. MasterPage behaves just like UserControl in your page.

Possible steps to implement this:

  1. Create a property or method on the MasterPage that enables you to make changes to the Label. E.g.:

    public void ChangeLabel(string label) { lblHeading.Text = label; }

  2. From your Page, get the reference to the MasterPage by using Page.Master property.

  3. Call the method define in 1) to change the MasterPage contents.
Adrian Godong
Additional info: you may need to cast Page.Master into your MasterPage type, try Coding the Wheel's link for instruction over how to do that.
Adrian Godong
+2  A: 

yes, you can in this very simple way........

((Label)Master.FindControl("lblHeading")).Text = "your new text";
Muhammad Akhtar