Sitefinity ASP.NET CMS
Support / Forums / Sitefinity 3.x: Developing with Sitefinity / Getting an image URL from the ImageSelector WebEditor?

Not answered Getting an image URL from the ImageSelector WebEditor?

Feed from this thread
  • Jay Jay's avatar

    Posted on Apr 27, 2009 (permalink)

    I'm trying to create a very simple custom control that will allow a user to select some images and links.  I'm using the ImageSelector WebEditor to display the nice Sitefinity interface for choosing an image from a library.  However, the control returns the GUID of the image instead of  the actual image URL.  How can I go about getting the actual image url?

    My code is below.  Any help is appreciated.

    1 <%@ Import Namespace="System.ComponentModel" %> 
    2  
    3 <script runat="server"
    4     [Category("Promo 1")] 
    5     [Telerik.Cms.Web.UI.WebEditor("Telerik.Cms.Web.UI.CmsUrlWebEditor, Telerik.Cms")] 
    6     public String LinkURL1 
    7     { 
    8         get 
    9         { 
    10             return hyperLink1.NavigateUrl; 
    11         } 
    12         set 
    13         { 
    14             hyperLink1.NavigateUrl = value
    15         } 
    16     } 
    17  
    18     [Category("Promo 1")] 
    19     [Telerik.Cms.Web.UI.WebEditor("Telerik.Libraries.WebControls.ImageSelector, Telerik.Libraries")] 
    20     public String ImageURL1 
    21     { 
    22         get 
    23         { 
    24             return hyperLink1.ImageUrl; 
    25         } 
    26         set 
    27         { 
    28             hyperLink1.ImageUrl = value
    29         } 
    30     } 
    31 </script> 
    32  
    33  
    34 <asp:HyperLink ID="hyperLink1" runat="server"></asp:HyperLink> 

    Reply

  • Gabe Sumner MVP Gabe Sumner's avatar

    Posted on Apr 27, 2009 (permalink)

    Hi Jay,

    Check out the following thread for ImageSelector usage:


    Does this help?  Also, some WebEditors are picky about the name of the underlying property.  For example, where you are using ImageUrl1, you might need to use SelectImage.

    If this doesn't help, let me know.

    Reply

  • Jay Jay's avatar

    Posted on Apr 27, 2009 (permalink)

    Thanks Gabe... the post you mentioned (and your site) were some of the resources I used to get as far as I am.  Unfortunately it's still not working.  I tried changing the name to SelectImage as you mentioned but it still does the same thing.  No matter what I do it always returns the GUID of the image when what I really want is the image path.

    Reply

  • Telerik Admin admin's avatar

    Posted on Apr 28, 2009 (permalink)

    Hi Jay,

    Here is an example on how to achieve the required functionality:

        [WebEditor("Telerik.Libraries.WebControls.ImageSelector, Telerik.Libraries")] 
        public string Value 
        { 
            get 
            { 
                return this.value; 
            } 
            set 
            { 
                this.value = value; 
            } 
        } 
     
        [WebEditor("Telerik.Cms.Web.UI.CmsUrlWebEditor, Telerik.Cms")]  
        public string LinkURL
        {    
            get  
            {  
                return hyperLink1.NavigateUrl;  
            }  
            set  
            {  
                hyperLink1.NavigateUrl = value;  
            }  
        }  
     
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!string.IsNullOrEmpty(this.Value)) 
            { 
                hyperLink1.ImageUrl = this.GetItemUrl(this.Value); 
            } 
        } 
     
        private string GetItemUrl(string val) 
        { 
            if (val.StartsWith("~/")) 
                return this.ResolveUrl(val); 
     
            if (val.StartsWith("[")) 
            { 
                int idx = val.IndexOf("]"); 
                string provider = val.Substring(1, idx - 1); 
                string strId = val.Substring(idx + 1); 
                Guid id = new Guid(strId); 
     
                if (ContentManager.Providers.ContainsKey(provider)) 
                { 
                    IContent cnt = ContentManager.Providers[provider].GetContent(id); 
                    if (cnt != null
                        return VirtualPathUtility.ToAbsolute(cnt.UrlWithExtension, this.Context.Request.ApplicationPath); 
                } 
            } 
            return val.ToString(); 
        } 
     
        private string value; 

    You need to get the image url using the returned provider name and ID (as it is done in GetItemUrl method).

    Do let us know if this helps.

    All the best,
    Pepi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Jay Jay's avatar

    Posted on Apr 28, 2009 (permalink)

    As always, your support is amazing.  This is perfect... thank you so much.

    Just a quick note for anyone else reading this... You'll need to import the "Telerik.Cms.Engine" namespace for this to work.

    Thanks again!!

    Reply

  • Jean avatar

    Posted on Sep 16, 2009 (permalink)


    Actually... you need to use the following namespaces...

    using

     

    Telerik.Cms.Web.UI;

     

    using

     

    System.ComponentModel;

     

    Reply

  • Frederico Fernandes avatar

    Posted on Jan 4, 2010 (permalink)

    Hi ,

    I want to do something similar but i want to save in a DB when i click in "i'm Done", how can i do it?

    Reply

  • Telerik Admin admin's avatar

    Posted on Jan 4, 2010 (permalink)

    Hi Frederico Fernandes,

    You need to create a custom ControlDesigner and override OnSaving() method. There you should add your logic to persists the data you want.

    sample


    public class TestDesigner: Telerik.Framework.Web.Design.ControlDesigner
    {

    public
    override void OnSaving()
      {
          base.OnSaving();
     
          DataContext dataContext = new DataContext();
             ....
                     ....
          dataContext.SubmitChanges();
      }
    }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

    Reply

  • Frederico Fernandes avatar

    Posted on Jan 4, 2010 (permalink)

    hi Ivan, i make my custom control designer but i can do
    [Telerik.Cms.Web.UI.WebEditor("Telerik.Cms.Web.UI.CmsUrlWebEditor, Telerik.Cms")] 
        public string LinkUrl 
        { 
            get { return _linkUrl; } 
            set { _linkUrl = value; } 
        } 

    the content does not apear.

    Reply

  • Telerik Admin admin's avatar

    Posted on Jan 4, 2010 (permalink)

    Hello Frederico Fernandes,

    As far as I see you have created WebEditor, not ControlDesigner. I suggest that you should go through the following posts Making Control Editing User-Friendly with Sitefinity Control Designers

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

    Reply

  • Frederico Fernandes avatar

    Posted on Jan 4, 2010 (permalink)

    Hi Ivan,

    I check the link you send but i want to know how i catch the button "i'm done" in advanced tab?

    Reply

  • Telerik Admin admin's avatar

    Posted on Jan 4, 2010 (permalink)

    Hello Frederico Fernandes,

    Please take a look at the previous post again where I suggested that you had to override OnSaving method. The "I'm done button" is one and it does not matter whether you are in advanced or basic tab.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

    Reply

  • Frederico Fernandes avatar

    Posted on Jan 4, 2010 (permalink)

    Hi Ivan,

    its strange but it hapens in basic tab the event onSave work but when i'm in advanced tab the event don't work.

    thanks for your help anyway. i'll try other way.

    Frederico Fernandes

    Reply

About Telerik

Telerik, the publisher of Sitefinity CMS, is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting and .NET ORMTFSCode Analysis and Web Application Testing tools. Building on its solid expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Created with passion, Telerik products help thousands of developers every day to be more productive and deliver reliable applications under budget and on time. Read more about Telerik

Copyright © 2002-2010 Telerik. All rights reserved. Powered by Sitefinity