我有以下环境:
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调用一个方法 - 但我想在这种情况下使用一个pull系统...
答案 0 :(得分:0)
您可以在母版页上使用MasterType
属性。
答案 1 :(得分:0)
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
}
}