Copied to clipboard

Flag this post as spam?

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


  • dnac 4 posts 34 karma points
    Jan 06, 2014 @ 21:11
    dnac
    0

    Passing parameter from code to .NET Macro

    In my .ascx code I want to enumerate over collection of nodes and add macro for each one of them, prototype code looks this way: 

    <% foreach (var node in MainColumnNodes)
           {
        %>   
               <umbraco:Macro DataSourceId="<%= node.Id %>" Alias="Richtext" runat="server"></umbraco:Macro>
        <%
           }
        %>

    I'm unable to succeed - <%= node.Id %> always gets encoded and passed as string not as exact value of enumerated node.Id. I'm not sure, but I think this part worked for me yesterday and magically stoped to be ok today :) I'm not sure if it's achievable - I've seen documentation on passing cookies / request / current node parameters, but they're all connected to context elements not to custom ones that I have in list.

    Other option of solving this would be to resign from having separate .ascx files for enumerated macros and do everything inline, but it would make this particular list macro grow to enormous size as the solution rises. I'd like to keep it separated to be able to decide which HTML code to render depending on document type of specific node. 

    Is it possible? Maybe I'm doing it wrong and there is another way of achieving the same results?

    Edit:

    I was able to do it with the approach suggested here: http://munkimagik.wordpress.com/2009/04/08/adding-umbraco-macro-dynamically-to-user-control/ : 

    <asp:PlaceHolder ID="MacroPlaceHolder" runat="server"></asp:PlaceHolder>

    and 

    protected void Page_Load(object sender, EventArgs e)
            {
                foreach (var node in MainColumnNodes)
                {
                    umbraco.presentation.templateControls.Macro mcr = new umbraco.presentation.templateControls.Macro();
                    mcr.Alias = "Richtext";
                    mcr.MacroAttributes.Add("datasourceid",node.Id.ToString());
                    this.MacroPlaceHolder.Controls.Add(mcr);
                }
            }

    It works fine, but I'd like to know if it's achievable directly in .ascx code or I have to stick with code behind version. 

Please Sign in or register to post replies

Write your reply to:

Draft