Master Page

W

Weston Fryatt

Can you change text or add controls dynamically on a Master Page (not in the
Content Place Holder)?
 
M

Mark Rae

Can you change text or add controls dynamically on a Master Page (not in
the Content Place Holder)?

Yes - a MasterPage is really just a particular kind of UserControl.

So, e.g. if the MasterPage had a Label called "lblHeading", you could do the
following in the Page_Load method of the ContentPage:

((Label)this.Master.FindControl("lblHeading")).Text = "Hello world";
 
J

Jesse Liberty

Yes, but if you anticipate it in advance, you can make the label's text a
property of the master page

public string LblHeading
{
get { return this.lblHeading.Text; }
set { this.lblHeading.Text = value; }
}

Then, in the content page, all you have to write is

this.Master.LblHeading = "Hello World";
 
M

Mark Rae

Yes, but if you anticipate it in advance, you can make the label's text a
property of the master page

public string LblHeading
{
get { return this.lblHeading.Text; }
set { this.lblHeading.Text = value; }
}

Then, in the content page, all you have to write is

this.Master.LblHeading = "Hello World";

Of course. A class is a class is a class...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top