Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing top master page properties in a nested master page code behind

I have a nested master page that has its own master page. The parent master page has a property defined in its code behind.

  Public ReadOnly Property SelectedPage() As String
    Get
      Return _selectedPage
    End Get
  End Property

How can I reference the parent master page's property from within either the child master page's code behind Page_Load or aspx template page?

like image 701
Dave Konopka Avatar asked Feb 18 '10 23:02

Dave Konopka


2 Answers

VB.Net:

DirectCast(Master, MyMastPageType).SelectedPage

C#:

((MyMastPageType)Master).SelectedPage

http://msdn.microsoft.com/en-us/library/system.web.ui.masterpage.master.aspx

like image 97
Russell Giddings Avatar answered Oct 01 '22 10:10

Russell Giddings


protected void Page_Load(object sender, EventArgs e)
{
  MyDemoMaster m = Master as MyDemoMaster;
  m.MyProperty = "My button text";
}

See:

like image 40
Asad Avatar answered Oct 01 '22 10:10

Asad