【问题标题】:Access in page an object from MasterPage that inherits from another MasterPage在页面中访问从另一个 MasterPage 继承的 MasterPage 的对象
【发布时间】:2011-10-31 12:27:02
【问题描述】:

我有以下层次结构:

Site.Master
    Site2.Master
        Page1.aspx
        Page2.aspx
    Page3.aspx
    Page4.aspx

在 Page3 和 Page4 上,我可以在 aspx 文件上使用 访问 Site.Master 上的对象。

如何访问 Page1 和 Page2 上的同一个对象?

我试过了:

1) 将 放在 Page1.aspx 上,但我收到错误消息。

2) 将 放在 Site2.Master 上,将 放在 Page1.aspx 上。 Page1.aspx 已打开,但我无法使用 Master 属性访问对象。

谢谢。

【问题讨论】:

    标签: asp.net master-pages


    【解决方案1】:
    public Site TopMasterPage
    {
        get
        {
            return (this.Master as Site) ?? this.Master.Master as Site;
        }
    }
    

    【讨论】:

    • 谢谢。对于其他人,我在“public partial class Page1 : System.Web.UI.Page {”之后在我的 Page1.aspx.cs 和 Page2.aspx.cs 上添加了这段代码,并使用 TopMasterPage.ObjectName 来访问对象。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-18
    • 1970-01-01
    • 1970-01-01
    • 2011-05-15
    • 1970-01-01
    • 2013-12-27
    相关资源
    最近更新 更多