繁体   English   中英

如何从MasterPage中ContentPlaceholder中的页面访问属性

[英]How do I access properties from page in ContentPlaceholder in my MasterPage

我有以下环境:

  • 具有contentPlacholder的母版
  • 使用此fooPage页并实现基类( fooPage )的多个页面
  • fooPage具有一定的属性( fooProperty

现在我想做类似的事情

public partial class FooMaster : System.Web.UI.MasterPage
{
    // this is originally from the designer-file
    protected global::System.Web.UI.WebControls.ContentPlaceHolder ContentPlaceHolder;

    protected override void OnPreRender(System.EventArgs e)
    {
        var fooPageInstance = this.ContentPlaceHolder as fooPage;
        var fooPropertyInstance = fooPageInstance.fooProperty;
        // TODO do something with the property
    }
}

显然这是行不通的-但是我该如何实现呢?

我知道另一种选择:使用fooProperty作为参数从contentPage中的masterPage调用一个方法-但在这种情况下,我想拥有一个拉式系统...

您可以在母版页上使用MasterType属性。

请参阅: http : //msdn.microsoft.com/en-us/library/c8y19k6h.aspx

public partial class FooMaster : System.Web.UI.MasterPage
{
    // this is originally from the designer-file
    protected global::System.Web.UI.WebControls.ContentPlaceHolder ContentPlaceHolder;

    protected override void OnPreRender(System.EventArgs e)
    {
        var fooPageInstance = this.ContentPlaceHolder.BindingContainer as FooPage;
        var fooPropertyInstance = fooPageInstance.fooProperty;
        // TODO do something with the property
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM