Master pages

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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
 
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
 
Back
Top