0
votes

I have a XSLT macro that renders some markup and .NET usercontrol macros in a loop. So thats multiple usercontrol macros inside a xslt macro:

<xsl:for-each select="$node/* [@isDoc]">
//Some markup etc...
  <xsl:value-of select="umbraco.library:RenderMacroContent('&lt;?UMBRACO_MACRO NodeId=&quot;@id&quot; macroAlias=&quot;LogTag&quot;&gt;&lt;/?UMBRACO_MACRO&gt;', @id)" disable-output-escaping="yes"/>
</xsl:for-each> 

The markup from the usercontrols markup is rendered just fine, but everything in the Page_load is not executed. Why is that?

Heres the usercontrol markup:

<div class="logTag" id="Tag" runat="server">
      <img src="someimage.png" alt="image"/>
</div>

And code-behind:

public int NodeId { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)return;

    var tools = new Tools();
    var userId = (Int32)Membership.GetUser().ProviderUserKey;
    Tag.Visible = tools.GetLog(NodeId, userId);
    Response.Write("Node=" + NodeId + " - User=" + userId + "<br />");
}

Neither the Response.Write or Tag.Visible is working. I've tried testing the usercontrol macro directly on a blank - works fine! Is this not possible, or am I doing something wrong?

1

1 Answers

2
votes

Unfortunately due to the nature of XSLT macros and where the render event is called in the page lifecycle means that the library.RenderMacroContent() method will not work inside XSLTs.

There is a workaround discussed on Hendy Racher's blog which is used to create "widgets" functionality, if this is what you are after. This utilises an ASP.NET repeater which injects the usercontrols at the correct phase of the page cycle to allow usercontrol macros to work. Otherwise, use the Macro Container datatype in Umbraco 4.7 and upwards, which allows drag-drop functionality of macros inside the Umbraco backoffice, and can be successfully rendered (usercontrols, Razor or XSLT) using an <umbraco:Item /> tag.