Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • webmonger 130 posts 285 karma points
    Feb 10, 2010 @ 23:26
    webmonger
    0

    Pass public variable in MasterPage to User Control Macro

    Hi

    I'm looking to send a public variable in a masterpage code behind to an umbraco macro.

    I've tried the suggestions on the advanced paramiters wiki page but can't get any of them to work.

    <umbraco:Macro Alias="AliasName" runat="server" PublicVariable="[#PublicVariable]"></umbraco:Macro>
    <umbraco:Macro Alias="AliasName" runat="server" PublicVariable="[$PublicVariable]"></umbraco:Macro>
    <umbraco:Macro Alias="AliasName" runat="server" PublicVariable="<%= PublicVariable %>"></umbraco:Macro>

    Could someone tell me if this is possible or do I need to include the usercontrols using the standard asp.net way?

    Cheers

    Jon

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Feb 11, 2010 @ 01:14
    Peter Gregory
    0

    Hi Jon

    Have a look at Code Expression builder.  There is a good writeup on how to use this with Umbraco on the Delphic Sage site.

    http://www.delphicsage.com/home/blog.aspx/d=854/title=Code_Expressions_to_Programmaticify_Your_Umbraco_Site

    It should sort out your codebehind variable woes.

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Feb 11, 2010 @ 10:06
    Morten Christensen
    1

    Hi Jon,

    It is my experience that programmatically adding parameters to a Macro only works if you create the Macro from your codebehind. As I recall it has something to do with the buildup of the Macro and when its loading/calling. Its been a while since I debugged it, but here is what worked for me:

    I have a standard <asp:PlaceHolder ID="macroContainer" runat="server"/> on my .ascx page. And I create the Macro in my codebehind:

    umbraco.presentation.templateControls.Macro mcr = new umbraco.presentation.templateControls.Macro();
    mcr.Alias = "BreadcrumbNav";
    mcr.MacroAttributes.Add("boolParam", "true");
    mcr.MacroAttributes.Add("IdParam", Id);
    this.macroContainer.Controls.Add(mcr);

    I have this inside  protected override void OnPreRender(EventArgs e)
    I can't remember if it makes a difference to place it inside the protected void Page_Load(object sender, EventArgs e) but try it out. Should work in both Masterpages and Usercontrols.

    - Morten

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Feb 11, 2010 @ 10:29
    Ismail Mayat
    0

    Morten,

    You live and learn have had need in past to do this but was'nt quite sure how to do it, just voted up your post.

    Regards

     

    Ismail

  • webmonger 130 posts 285 karma points
    Feb 11, 2010 @ 11:57
    webmonger
    0

    Hey

    Thanks for your replies. I've had a read through and had a chat with a friend and I think I may be going around this in the wrong way.

    I've accepted Peters answer as the solution because it answers the question but i think i'm going to change the architecture of what i'm doing so there is no reliance on the master page.

    The user control should probably be autonomous so I think I'll change it so it goes and gets the information it self rather than relying on the master page sending it the information.

    Cheers

    Jon

     

Please Sign in or register to post replies

Write your reply to:

Draft