Copied to clipboard

Flag this post as spam?

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


  • ianhoughton 281 posts 605 karma points c-trib
    Nov 23, 2012 @ 15:19
    ianhoughton
    0

    Get URL picker values inside a repeater

    I'm trying to output the Url from the uComponents URL picker inside of a ASP.NET repeater.

    <a class="cnt-more" href="<%# ((Node)Container.DataItem).GetProperty("quoteLink").Value.ToString() %>">
        <p class="xt"><%#((Node)Container.DataItem).GetProperty("quoteLinkText").Value.ToString()%></p>
        <p class="vp">Get a quote</p>
    </a>

    I can get the complete output from the picker but not the Url.

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Nov 23, 2012 @ 16:33
    Stefan Kip
    1

    I'm using the following method to resolve UrlPicker values to a POCO:

    /// <summary>
    /// Resolves the value of a UrlPicker datatype to a .NET object
    /// </summary>
    /// <param name="urlPickerXml">The value of the UrlPicker in XML format</param>
    /// <returns>A UrlPicker .NET object</returns>
    public static UrlPicker ResolveUrlPicker(string urlPickerXml)
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(urlPickerXml);
    
        UrlPicker urlPicker = new UrlPicker()
        {
            Mode = (UrlPicker.UrlPickerMode)Enum.Parse(typeof(UrlPicker.UrlPickerMode), xmlDoc.SelectSingleNode("//url-picker").Attributes["mode"].InnerText),
            Url = xmlDoc.SelectSingleNode("//url").InnerText,
            NewWindow = bool.Parse(xmlDoc.SelectSingleNode("//new-window").InnerText),
        };
        XmlNode linkTitleElement = xmlDoc.SelectSingleNode("//link-title");
        if(linkTitleElement != null)
            urlPicker.LinkTitle = linkTitleElement.InnerText;
        if (!string.IsNullOrEmpty(xmlDoc.SelectSingleNode("//node-id").InnerText))
        {
            urlPicker.NodeId = int.Parse(xmlDoc.SelectSingleNode("//node-id").InnerText);
            urlPicker.Url = umbraco.library.NiceUrl(urlPicker.NodeId.Value);
        }
    
        return urlPicker;
    }
    

    And this is the POCO class:

    /// <summary>
    /// POCO for UrlPicker
    /// </summary>
    public class UrlPicker
    {
        /// <summary>
        ///  The mode (url/content/media/upload)
        /// </summary>
        public UrlPickerMode Mode { get; set; }
        /// <summary>
        /// The url
        /// </summary>
        public string Url { get; set; }
        /// <summary>
        /// Open in new window?
        /// </summary>
        public bool NewWindow { get; set; }
        /// <summary>
        /// The link title
        /// </summary>
        public string LinkTitle { get; set; }
        /// <summary>
        /// The node id
        /// </summary>
        public int? NodeId { get; set; }
    
        /// <summary>
        /// Enum for UrlPicker modes
        /// </summary>
        public enum UrlPickerMode { URL, Content, Media, Upload }
    }
Please Sign in or register to post replies

Write your reply to:

Draft