Copied to clipboard

Flag this post as spam?

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


  • Waqar Zafar 14 posts 34 karma points
    Feb 23, 2011 @ 17:40
    Waqar Zafar
    0

    Multi-Node Tree Picker in .ascx code behind

    Hi,

    I am quite new to umbraco. I am using uCompontents but struggling to access it in code behind .ascx control. Can't find anywhere how to access it. Can anyone please let me know which .dll files to reference to access uComponents more specifically I need to access related nodes from Multi-Node Tree Picker in code behind.

    I am using Multi-Node Tree Picker as csv so an example with that would be helpful.

    Thanks.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 24, 2011 @ 13:17
    Lee Kelleher
    1

    Hi Wagar,

    Here's an example of how to use the MNTP value (CSV) from a user-control's code-behind.  Since you are using uComponents, we can make use of uQuery too!

    using System;
    using uComponents.Core;
    using uComponents.Core.uQueryExtensions;
    using umbraco.presentation.nodeFactory;
    
    public partial class usercontrols_WebUserControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // get the current node
            var currentNode = Node.GetCurrent();
    
            // use uQuery to get the value from MNTP
            var csv = currentNode.GetPropertyAsString("treePicker");
    
            // use uQuery to get the nodes by CSV
            var nodes = uQuery.GetNodesByCsv(csv);
    
            // loop through each of the nodes
            foreach (var node in nodes)
            {
                // do whatever you like with the node!
                Response.Write(node.Name + "<br />");
            }
        }
    }

    You will need to reference the "uComponents.Core.dll", (along with "umbraco.dll") in your Visual Studio project.

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft