Master pages

G

Guest

How do I pass user defined data between a content page and a master page?
My content page needs to change the menu options in my masterpage.
 
G

Guest

Hi Arne,
your content page contains property named Master which allows you to get
reference to your master page. This property returns instance of MasterPage
class by default so you have to cast it to your master page class.

If you want to have strongly typed system you have to insert MasterType
directive to your content page. After that Master property will return
instance of type defined in this directive.

So now you have an idea how to access Master page but this is still not end
of the story ;) You have to define public properties and methods on your
master page to allow modifications to UI outside of this class (all UI
elements are marked as protected by default).

Regards,
Ladislav
 
G

Guest

Hi Arne,
your content page contains property named Master which allows you to get
reference to your master page. This property returns instance of MasterPage
class by default so you have to cast it to your master page class.

If you want to have strongly typed system you have to insert MasterType
directive to your content page. After that Master property will return
instance of type defined in this directive.

So now you have an idea how to access Master page but this is still not end
of the story ;) You have to define public properties and methods on your
master page to allow modifications to UI outside of this class (all UI
elements are marked as protected by default).

Regards,
Ladislav





- Show quoted text -

Example:

-- Master --

public partial class Site1 : System.Web.UI.MasterPage
{
private int menu_id;

protected void Page_Load(object sender, EventArgs e)
{
if (menu_id == 0) {
.....
}
}

// this is an example of public property to set menu_id
public int MenuID
{
set { this.menu_id = value; }
}
}

Now in the content page you can set menu_id

Site1 m = (Site1)(Page.Master);
m.MenuID = 0; // homepage

That's all
 

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,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top