Copied to clipboard

Flag this post as spam?

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


  • Øyvind Kristiansen 14 posts 54 karma points
    Sep 08, 2010 @ 14:38
    Øyvind Kristiansen
    0

    Passing parameters to .NET user control

    I am using Multi-Node Tree Picker and try to pass the node IDs of the selected nodes to a .NET user control. The alias of the property in the document type is selectedNodes. In the template, I call the macro with the following code:

    <umbraco:Macro SelectedNodes="[$selectedNodes]" Alias="[.NET]SelectedtNodesToBeDisplayedAsCurrentNews"
     runat="server"></umbraco:Macro>

    In my user control, I have a property called SelectedNodes. When i run the page, the value of the SelectedNodes property is

    [$selectedNodes]

    I think the problem might be that when setting up the macro in Developer, i have the wrong type selected for the parameter. I have tried using many of the available types though, with varying results. With many of the types I get a conversion error when using ?umbdebugshowtrace=true, but when i use text, i get the result mentioned above.

    I am using Umbraco v4.5.2 and uComponents v1.0BETA.

    Any suggestions to what I'm doing wrong and what I have to do to be able to use the results from the Tree Picker in my user control would be greatly appreciated!

  • Ronnie Hegelund 48 posts 710 karma points
    Sep 08, 2010 @ 21:07
    Ronnie Hegelund
    0

    Hey Øyvind, the MNTP is saving data default as XML, change this to CSV should do the trick..

    /ronnie

  • Øyvind Kristiansen 14 posts 54 karma points
    Sep 09, 2010 @ 09:01
    Øyvind Kristiansen
    0

    Ronnie, thank you for your reply.

    I've looked in data types, and there is no option here to save as CSV. Also, under macro properties, I cannot choose CSV. How do i change to CSV?

    By the way, I'm using legacy schema for .NET 3.5.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 09, 2010 @ 09:26
    Jeroen Breuer
    0

    The beta doesn't support CSV yet I think. If you use the latest changeset it does work: http://ucomponents.codeplex.com/SourceControl/list/changesets

    However I think you're code should work, but [$selectedNodes] just doesn't support passing XML data. You could create an issue for this on codeplex: http://umbraco.codeplex.com/WorkItem/Create.

    Jeroen

  • Øyvind Kristiansen 14 posts 54 karma points
    Sep 09, 2010 @ 10:29
    Øyvind Kristiansen
    0

    Ok, this confirms my suspicions. My colleague's workaround is to recursively look for the property upwards in the node hierarchy until the correct property is found or you hit the root node. I paste the code here so that others with the same issues might benefit from it:

     

            public static int FindFirstNodeWithThisPropertyRecursively(Node _nCurrentNode, String _sPropertyName)
    {
    if (_nCurrentNode != null)
    {
    if (_nCurrentNode.Parent != null)
    {
    String _sType = _nCurrentNode.Parent.NodeTypeAlias;
    if (_nCurrentNode.Parent.GetProperty(_sPropertyName) != null)
    {
    return _nCurrentNode.Parent.Id;
    }
    else
    {
    return FindFirstNodeWithThisPropertyRecursively(_nCurrentNode.Parent, _sPropertyName);
    }
    }
    }
    return -1;
    }

    public static Nodes GetSelectedNodesFromMultiNodeTreePicker(int _iFoundNodeId, String _sSelectedNodesPropertyName)
    {
    if (_iFoundNodeId != -1)
    {
    try
    {
    Node _nFoundNode = new Node(_iFoundNodeId);
    if (_nFoundNode != null)
    {
    var _pSelectedNodes = _nFoundNode.GetProperty(_sSelectedNodesPropertyName);
    if (_pSelectedNodes != null)
    {
    String _sValue = _pSelectedNodes.Value.ToString();
    XmlDocument _xmlDocument = new XmlDocument();
    _xmlDocument.LoadXml(_sValue);
    XmlNodeList _xmlNodeList = _xmlDocument.SelectNodes("//nodeId");
    Nodes _nNodesToReturn = new Nodes();
    foreach (XmlNode _xmlNode in _xmlNodeList)
    {
    int _iXmlNodeId = 0;
    int.TryParse(_xmlNode.InnerText, out _iXmlNodeId);
    if (_iXmlNodeId != 0)
    {
    _nNodesToReturn.Add(new Node(_iXmlNodeId));
    }
    }
    return _nNodesToReturn;
    }
    }
    }
    catch
    {
    return null;
    }

    }
    return null;
    }
Please Sign in or register to post replies

Write your reply to:

Draft