Dave Konopka
Dave Konopka

Reputation: 1255

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?

Upvotes: 6

Views: 4269

Answers (4)

Guven Sezgin Kurt
Guven Sezgin Kurt

Reputation: 1339

Here is how I use

MasterPage tmp = this.Master;
while (tmp.Master != null)
{
    tmp = tmp.Master;
}

Upvotes: 0

Russell Giddings
Russell Giddings

Reputation: 9011

VB.Net:

DirectCast(Master, MyMastPageType).SelectedPage

C#:

((MyMastPageType)Master).SelectedPage

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

Upvotes: 6

SLaks
SLaks

Reputation: 888213

Like this:

DirectCast(MyMastPageType, Master).SelectedPage

Upvotes: 0

Asad
Asad

Reputation: 21938

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

See:

Upvotes: 1

Related Questions