1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to add properties to ASCX control?

How to add properties to ASCX control?

21 posts, 0 answered
  1. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    08 Jun 2009
    Link to this post

    Hello ALL!!!

    I just created my own ASCX control and I want to creates properties (this properties must contain path to ASPX page that contain more information with my control) such in NewsView Control?

  2. Rein
    Rein avatar
    22 posts
    Registered:
    07 Oct 2008
    08 Jun 2009
    Link to this post
    You can expose usercontrol properties like this in your usercontrol's code:

    C# 3.5
    public string MyProperty { getset; } 

    C# 2.0
    private string _MyProperty; 
    public string MyProperty 
       get { return _MyProperty; } 
       set { _MyProperty = value; } 

  3. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    08 Jun 2009
    Link to this post
    I want to create in CMS in edit mode button which select a URL path
  4. Rein
    Rein avatar
    22 posts
    Registered:
    07 Oct 2008
    08 Jun 2009
    Link to this post
    Please provide a more detailed description of what you are trying to accomplish. Maybe you could show us some of the code you have so far?
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    08 Jun 2009
    Link to this post
    Hello rent,

    You need to use Web Editor to get the url. It depends whether you want to select the SiteMapUrl or another.
    Here is an example of WebEditor that will return the url of a SiteMap node.

    [WebEditor("Telerik.Cms.Web.UI.UrlEditorWrapper, Telerik.Cms")] 
    [Browsable(true)] 
    [Category("Navigation")] 
        public string NodeUrl 
        { 
            get 
            { 
                return this.nodeUrl; 
            } 
            set 
            { 
                this.nodeUrl = value; 
            } 
        } 
      
         private string nodeUrl; 


    All the best,
    Ivan Dimitrov
    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.
  6. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    10 Jun 2009
    Link to this post

    Thanks for reply

    And now I have one more question: 

    How to show near NodeUrl label a help link when pressed tis show help tolltip such in a standard Sitefinity controls?

  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    10 Jun 2009
    Link to this post
    Hello rent,

    Add Description attribute at the same way as we have done for Category.

    [Description("some description here")] 

    Greetings,
    Ivan Dimitrov
    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.
  8. Dennis
    Dennis avatar
    19 posts
    Registered:
    26 May 2009
    10 Jun 2009
    Link to this post
    How do I do the same with an image url property, so that I can select an image from my "Images & Documents" lists?

    Another question - When I try to insert a hyperlink in the "Generic Content", how do i then target a document in my "Images & Documents" lists - Apparently I can only selecs files from the File System.

    Regards, Dennis
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    10 Jun 2009
    Link to this post
    Hello Dennis,

    How do I do the same with an image url property, so that I can select an image from my "Images & Documents" lists?

    You can use [WebEditor("Telerik.Libraries.WebControls.ImageSelector, Telerik.Libraries")]

    When I try to insert a hyperlink in the "Generic Content", how do i then target a document in my "Images & Documents" lists - Apparently I can only selecs files from the File System.

    You should create a custom tool for radEditor and use the same templates as you have for the InsertLink tool. Afterwords declare the following code in your tool template.

    /Sitefinity/Admin/ControlTemplates/Pages/Dialogs/LinksEditorDialog.ascx

    <li id="li1"
            
                <asp:Label ID="Label4" runat="server" Text="ImageURL" AssociatedControlID="TextBox1"></asp:Label> 
                <asp:TextBox runat="server" ID="TextBox1" onkeydown="requiredFieldsValidate();" onkeyup="requiredFieldsValidate(); return false; " onfocus="requiredFieldsValidate(); return false; " onblur="requiredFieldsValidate(); return false; "></asp:TextBox> 
                <asp:Label ID="Label5" runat="server" Text="<%$Resources:Or %>"></asp:Label> 
                <sfLib:ButtonSelector ID="ButtonSelector1" runat="server" ButtonText="Select from Libraries or FilesSystem" WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ImageDialog.aspx" AssociatedControls="TextBox1" /> 
                <class="example"><asp:Literal ID="Literal3" runat="server" Text="<%$Resources:UrlExpl %>" ></asp:Literal></p
       
          </li> 


    Thus you will be able to insert a link from images and documents libraries.

    Sincerely yours,
    Ivan Dimitrov
    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.
  10. Dennis
    Dennis avatar
    19 posts
    Registered:
    26 May 2009
    10 Jun 2009
    Link to this post
    Thank you for the fast reply: When I use your approach for image url selector I am able to browse and select an image from the "Images & Documents" section but the string returned (image url) is the following format:

    UserControls/Millers/%5BLibraries%5D72d18cbe-f8f0-4b6e-9d1e-27239609b451

    Where as if I insert it using your image control then image reference is:

    Libraries/Fleet_Images/OW_Atlantic.sflb.ashx

    Any ideas on how to resolve that?

    Regards, Dennis
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    10 Jun 2009
    Link to this post
    Hi Dennis,

    Libraries is the provider and then it is followed by the guid. The link should be well formed after you save the content item. I did not faced any problems with the rendering as well.

    Kind regards,
    Ivan Dimitrov
    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.
  12. Dennis
    Dennis avatar
    19 posts
    Registered:
    26 May 2009
    10 Jun 2009
    Link to this post
    Hello Ivan

    Thanks for the reply, but I still have problems.

    I have a property like this:

    [

    WebEditor("Telerik.Libraries.WebControls.ImageSelector, Telerik.Libraries")]
    public string Image { get; set; }

    When the control loads, I set the ImageUrl like this:

     

    imgContact.ImageUrl = Image;

    When I view the webpage it does not show an image. If I select properties to see which location it expects it looks like this:

    http://siteurl/UserControls/Millers/%5BLibraries%5D2507c3cd-b1f9-4a5a-901a-b7b87b91751f

    Maybe I need to do some decoding when setting the property? Hope you can help.

    Regards, Dennis

  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    12 Jun 2009
    Link to this post
    Hello Dennis,

    In your HyperlinkManager use the declaration below

    <sfLib:ButtonSelector ID="ButtonSelector1" runat="server" ButtonText="Select from Libraries or FilesSystem" WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ImageDialog.aspx" AssociatedControls="TextBox1" />  

    As for the WebEditor you should convert the link. Below is a sample code:

       private string GetUrl(string value) 
        { 
            // if our value starts with ~/   
            // we return url  
            if (value.StartsWith("~/")) 
                return this.ResolveUrl(value); 
     
     
            if (value.StartsWith("[")) 
            { 
                int idx = value.IndexOf("]"); 
                //getting the provider [Libraries]  
                string provider = value.Substring(1, idx - 1); 
                string strId = value.Substring(idx + 1); 
                Guid id = new Guid(strId); 
     
                if (Telerik.Cms.Engine.ContentManager.Providers.ContainsKey(provider)) 
                { 
                    Telerik.Cms.Engine.IContent cnt = Telerik.Cms.Engine.ContentManager.Providers[provider].GetContent(id); 
                    if (cnt != null
                        return VirtualPathUtility.ToAbsolute(cnt.UrlWithExtension, this.Context.Request.ApplicationPath); 
                } 
            } 
            return value.ToString(); 
        }  


    Sincerely yours,
    Ivan Dimitrov
    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.
  14. Garry Clark
    Garry Clark avatar
    26 posts
    Registered:
    27 Jan 2005
    08 Aug 2009
    Link to this post
    Ivan,
    Can I do something similar in a Pluggable Module Admin control? I am trying to do something like this.
    /// <summary>  
            /// Gets the Text Price  
            /// </summary>  
            /// <value>The Name Textbox.</value>  
            protected virtual Telerik.Web.UI.RadTextBox textImage  
            {  
                get 
                {  
                    return base.Container.GetControl<Telerik.Web.UI.RadTextBox>("textImage"true);  
                }  
            }  
            /// <summary>  
            /// Gets the Text Price  
            /// </summary>  
            /// <value>The Name Textbox.</value>  
            protected virtual Telerik.Libraries.WebControls.ButtonSelector btnSelect  
            {  
                get 
                {  
                    return base.Container.GetControl<Telerik.Libraries.WebControls.ButtonSelector>("btnSelect"true);  
                }  
            } 

    Initialize Controls
    btnSelect.WindowNavigateUrl = "~/Sitefinity/UserControls/Dialogs/ImageDialog.aspx";  
                btnSelect.ButtonText = "Select from Libraries or FilesSystem";  
                btnSelect.AssociatedControls = "textImage"

    Template
    <telerik:RadTextBox ID="textImage" runat="server" Skin="Office2007" Width="150px" ReadOnly="true" /> 
                                <sfLib:ButtonSelector ID="btnSelect" runat="server" /> 

    Everything works as expected, but the Image Selector dialog does not return an image url to populate the textImage box. Is there a event or something I need to subscribe to?

    Any help would greatly be appreciated.
  15. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    12 Aug 2009
    Link to this post
    Hi Garry Clark,

    There should not be any difference if the button selector is in the custom control. I will try to set up similar environment and get back to you.

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  16. Dennis
    Dennis avatar
    19 posts
    Registered:
    26 May 2009
    04 Sep 2009
    Link to this post
    Hi,

    I'm using the new 3.7 version (don't know if that makes a difference but can't remember seing this problem earlier)

    I have a custom control for opening hours with the properties "Monday", "Tuesday" ......

    I have declared the properties in logical order, but in SiteFinity they show up in random order. Not alphabettically and not in the order I declared.

    This is quite confusing. Is this a bug or can I do something to control the order?

    Regards, Dennis
  17. Garry Clark
    Garry Clark avatar
    26 posts
    Registered:
    27 Jan 2005
    04 Sep 2009
    Link to this post
    Dennis,
    I am not sure on your implementation, but one thing you could look at doing is storing them in a Dictionary and use the key to sort on.

    So other words you would have something like this.

    Dictionary<intstring> sample = new Dictionary<intstring>();  
                    sample.Add(1, "Monday");  
                    sample.Add(2, "Tuesday");  
                    sample.Add(3, "Wednesday");  
                    sample.Add(4, "Thursday");  
                    sample.Add(5, "Friday");  
                     

    And I think this is the correct Blog on how to use Complex Properties.
    http://www.sitefinity.com/blogs/ivan/posts/07-05-24/working_with_complex_properties_in_custom_public_controls_webtypeeditor.aspx

    Anyhow man I hope this helps.
  18. Dennis
    Dennis avatar
    19 posts
    Registered:
    26 May 2009
    04 Sep 2009
    Link to this post
    I don't use complex types - I just implement them as individual properties like this:

    [

    Category("Opening Hours")]

     

     

     

    public string Monday { get; set; }

     

     

     

     

    [Category("Opening Hours")]

     

     

     

    public string Tuesday { get; set; }

    and so forth...

    But if I do it like this I can not control the order they will appear in in SiteFinity?

    Do I have to use the method you described?

    Regards, Dennis

     

     

     

  19. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Sep 2009
    Link to this post
    Hi Dennis,

    Managing of the Properties tab for user and custom controls will be available from Sitefinity 4.0. The current implementation and API does not allow proper solution.

    Best wishes,
    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.
  20. Garry Clark
    Garry Clark avatar
    26 posts
    Registered:
    27 Jan 2005
    04 Sep 2009
    Link to this post
    So Ivan,
    Until 4.0 is released would a complex property be the best solution for him?
  21. Garry Clark
    Garry Clark avatar
    26 posts
    Registered:
    27 Jan 2005
    04 Sep 2009
    Link to this post
    Sorry I got Reply button happy it seems. I meant to also say that now I kind of see what you are going after Dennis I would possibly do something like this instead.

    Dictionary<string,string> sample = new Dictionary<string,string>;  
                    sample.Add("Monday","8:00am to 3:00pm");  
                    sample.Add("Tuesday","8:00am to 5:00pm");  
                    sample.Add("Wednesday","8:00am to 4:00pm");  
                    sample.Add("Thursday","8:00am to 6:00pm");  
                    sample.Add("Friday","8:00am to 6:00pm"); 

    and then are you wanting the user to be able to change the hours? If so you could then possibly store and retrieve them as a delimented string such as this "Monday,8:00am to 3:00pm|Tuesday,8:00am to 5:00pm|etc..." and then simply do something like this.

    string stringArray = "Monday,8:00am to 3:30pm|Tuesday,9:00am to 5:00pm";  
                    Dictionary<string,string> OpeningHours = new Dictionary<string,string>;  
                    string[] DayTime = stringArray.Split(new char[] { '|' });  
                    foreach (string singleDay in Days)  
                    {  
                        string[] t = singleDay.Split(new char[]{','});  
                        if (singleDay.Contains(","))  
                        {  
                            OpeningHours.Add(t[0],t[1]);  
                        }  
                    } 

    That way you can still use a single property of type string in Sitefinity, but then still be able to display the value in any order you wish. I believe you would have to use a Custom Editor though in order for people to nicely be able to modify the values of the property, but there are plenty of posts on how to do so and its not that hard.

    Anyhow hopefully this will help you in some way!
Register for webinar
21 posts, 0 answered