在嵌套的母版页代码中访问*母版页属性

时间:2021-10-02 15:53:21

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?

如何在Page_Load或aspx模板页面后面的子母版页面代码中引用父母版主页面的属性?

4 个解决方案

#1


6  

VB.Net:

DirectCast(Master, MyMastPageType).SelectedPage

C#:

((MyMastPageType)Master).SelectedPage

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

#2


1  

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

See:

#3


0  

Like this:

DirectCast(MyMastPageType, Master).SelectedPage

#4


0  

Here is how I use

这是我的使用方法

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

#1


6  

VB.Net:

DirectCast(Master, MyMastPageType).SelectedPage

C#:

((MyMastPageType)Master).SelectedPage

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

#2


1  

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

See:

#3


0  

Like this:

DirectCast(MyMastPageType, Master).SelectedPage

#4


0  

Here is how I use

这是我的使用方法

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