c# - How do I get access to master page properties via user control markup? -
i have been searching internet , find resolves issue of accessing master page properties user control's code behind. unable find solution user control can have access master page's properties within markup.
background:
the master page dynamically adds user control onto page. master page has 2 properties user control needs access via markup.
here code represent problem:
master page's code behind properties:
public imodule module     {                 {             return mycontext.current.module;         }     }      public idictionary<string, object> arguments     {                 {             return mycontext.current.arguments;         }     }   master page dynamically adds control in code behind (it has dynamically added in master page's code behind):
protected override void oninit(eventargs e)         {             base.oninit(e);              if (!(page vehicleform) && !(page vsrmanageform) && !(page vpbmanageform))             {                 menutab view = (menutab)this.loadview(plhmenu, "~/controls/menutab.ascx", "", mycontext.current.module);             }         }   user control's markup:
<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>   error:
compiler error message: cs0103: name 'arguments' not exist in current context   question: how access <%# arguments %> , <%# module %> master page properties user control?
it might possbile (have not tested though) this:
arguments="<%# ((masterpagetype)this.page.master).arguments %>"   although not right. might want redesign way control gets data. or atthe least same somewhere in code behind , verify whether current masterpage of expected type.
update. final solution op used incorporated ideas above, , resulted in having properties below declared in control:
public idictionary<string, object> arguments {         {         masterpagetype master = this.page.master masterpagetype;         if (master != null)         {             return master.arguments;         }         else         {             return null;         }     } }      
Comments
Post a Comment