Copied to clipboard

Flag this post as spam?

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


  • Umbraco 137 posts 294 karma points
    Jul 27, 2012 @ 12:40
    Umbraco
    0

    How do I programmatically pass a parameter to a macro user control on the page?

    Given a macro on the master page, that has a parameter "test", how do I set test programmatically?

    <umbraco:Macro runat="server" ID="MyMacro"Alias="MyMacro" />

    I can set it declaratively by adding an attribute to the mark-up:

    <umbraco:Macro runat="server" ID="MyMacro"Alias="MyMacro" Test="42" />

    This way, I can use the value in XSLT.

    I tried to set the parameter from code (in Page_PreLoad, Page_Load or Page_PreRender) in the following ways:

    MyMacro.MacroAttributes.Add("Test", 42);
    MyMacro.Attributes.Add("Test", "42");

    But this way, although I get no exceptions, I also can't use the value in XSLT inside the macro. 

    This is not in the documentation as far as I can see, so I am stuck on this issue for now.

  • Biagio Arobba 16 posts 36 karma points
    Oct 17, 2013 @ 00:41
    Biagio Arobba
    0

    Hi, I'm coming across the same issue.

    I know this post is over a year old, but it might be useful to continue this thread if others have the same issue.

    Here is as far as I have gotten:

    The macro attributes are collected at PreInit, because the macro control call EnsureChildControls... which calls CreateChildControls. At that point the Macro class is used, and Macro's renderMacro() function will either return your control (where it will go through the normal events), or return a special "cached" control, or an empty literal control. So, the <umbraco:Macro /> control basically takes over before MasterPage's Page_Init function can be called.

    One possibility, I suppose is to use a placeholder control and then insert the macro programatically.

    Otherwise, have you found out how to modify the Attributes for a Macro control that was added to the masterpage? The Macro has special attribute values like [#...], and [@...], but I haven't come across any special attribute for calling a function or accessing public MasterPage properties.

Please Sign in or register to post replies

Write your reply to:

Draft