【发布时间】:2014-06-27 11:08:43
【问题描述】:
我一直在搜索互联网,我发现大多数解决了从用户控件代码访问母版页属性的问题。但是我找不到用户控件可以访问标记内的母版页属性的解决方案。
背景:
母版页动态地将用户控件添加到页面上。 母版页有两个属性,用户控件需要通过标记访问它们。
这里有一些代码来代表我的问题:
母版页属性背后的代码:
public IModule Module
{
get
{
return MyContext.Current.Module;
}
}
public IDictionary<string, object> Arguments
{
get
{
return MyContext.Current.Arguments;
}
}
母版页在后面的代码中动态添加到控件(必须在母版页的代码后面动态添加):
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (!(Page is VehicleForm) && !(Page is VsrManageForm) && !(Page is VpbManageForm))
{
MenuTab view = (MenuTab)this.LoadView(plhMenu, "~/Controls/MenuTab.ascx", "", MyContext.Current.Module);
}
}
用户控件的标记:
<web:FlowLink class="tools__lnk" arguments="<%# Arguments %>" id="flowLink1" runat="server" contextmodule='<%# Module %>' flowcall="FavouritesView" title="" rel="nofollow" ClientIDMode="Omitted">Shortlist</web:FlowLink>
<web:FlowLink class="tools__lnk" arguments="<%# Arguments %>" id="flowLink2" runat="server" contextmodule='<%# Module %>' flowcall="CompareView" title="" rel="nofollow" ClientIDMode="Omitted">Compare</web:FlowLink>
<web:FlowLink class="tools__lnk" arguments="<%# Arguments %>" id="flowLink5" runat="server" contextmodule='<%# Module %>' flowcall="UserView" title="" rel="nofollow" ClientIDMode="Omitted">Account</web:FlowLink>
错误:
Compiler Error Message: CS0103: The name 'Arguments' does not exist in the current context
问题: 如何从用户控件访问 和 母版页属性?
【问题讨论】: