如何从我的MasterPage的ContentPlaceholder中的页面访问属性 [英] How do I access properties from page in ContentPlaceholder in my MasterPage
本文介绍了如何从我的MasterPage的ContentPlaceholder中的页面访问属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下环境:
- 具有contentPlacholder的母版页
- 使用此母版页并实现基本类(
fooPage
)的多个页面 -
fooPage
具有特定属性(fooProperty
)
- masterpage with a contentPlacholder
- multiple pages which use this masterpage and implement a base-class (
fooPage
) fooPage
has a certain property (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
}
}
显然这行不通-但是我怎么能做到这一点?
Obviously this is not going to work - but how can I achieve this?
我知道另一种选择:使用fooProperty
作为参数从contentPage中的masterPage调用一个方法-但在这种情况下,我想拥有一个拉式系统...
I know the alternative: call a method from the masterPage in the contentPage with fooProperty
as a parameter - but i would like to rather have a pull-system in this case...
推荐答案
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
}
}
这篇关于如何从我的MasterPage的ContentPlaceholder中的页面访问属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文