More in this section

Forums / Developing with Sitefinity / How to use image selector and page selector in my custom Control in 4.1

How to use image selector and page selector in my custom Control in 4.1

4 posts, 0 answered
  1. Pravat
    Pravat avatar
    59 posts
    Registered:
    22 Jun 2010
    07 Jul 2011
    Link to this post
    Hi Team,

    I have develop lot of site by using sitefinity 3.7. Now I want to use sitefinity 4.1. Below code i have used to build site header custom control in 3.7. I have a image selector and a page selector in my site header custom control. How can i achieve it on 4.1.Please help.....

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using Telerik.Cms.Web.UI;
    using Telerik.Cms;
    using Telerik.Libraries;
    using Telerik.Cms.Engine;
      
      
      
    public partial class Sitefinity_UserControls_CustomControls_SiteHeader : System.Web.UI.UserControl
    {
        string headerImage;
        Guid imageUrl;
      
        [Category("Custom Attributes")]
        [DisplayName("Image Name")]
        [Description("The Guid of the image to be displayed on the header.")]
        [WebEditor("Telerik.Libraries.WebControls.ImageSelector, Telerik.Libraries")]
        public string HeaderImage
        {
            get { return headerImage; }
            set { headerImage = value; }
        }
      
        [Category("Custom Attributes")]
        [DisplayName("Redirect Url")]
        [Description("Index page of the header to be redirected on click of Image.")]
        [WebEditor("PageIDWebEditor, App_Code")]
        public Guid ImageUrl
        {
            get { return imageUrl; }
            set { imageUrl = value; }
        }
      
        protected void Page_Load(object sender, EventArgs e)
        {
            if (imageUrl != Guid.Empty)
            {
                CmsManager cMgr = new CmsManager();
                ICmsPage page = cMgr.GetPages().Cast<ICmsPage>().Where(x => x.ID == imageUrl).FirstOrDefault();
                if (page != null)
                {
                    hlHeader.NavigateUrl = page.StaticUrl;
                }
      
            }
      
            if (!string.IsNullOrEmpty(headerImage))
            {
                LibraryManager libMgr = new LibraryManager();
                headerImage = headerImage.Replace("[Libraries]", string.Empty);
                IContent content = libMgr.GetContent(new Guid(headerImage));
                string imgUrl = string.Empty;
                if (content != null)
                {
                    imgUrl = content.UrlWithExtension;
                    imgLogo.ImageUrl = imgUrl;
                }
            }
        }
    }
    Thanks & Regards,
    Pravat Sharma
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    07 Jul 2011
    Link to this post
    Hi Pravat,

    To get a selector you need to create ControlDesigner for your widget. You will find a sample implementation here.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Pravat
    Pravat avatar
    59 posts
    Registered:
    22 Jun 2010
    11 Aug 2011
    Link to this post
    Hi Ivan,
                can you send me some sample code of ControlDesigner please.

    Regards,
    Pravat Sharma
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    11 Aug 2011
    Link to this post
    Hi Pravat,

    There is a sample code in our documentation and SDK.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered