More in this section

Forums / Developing with Sitefinity / Complex Properties Question

Complex Properties Question

7 posts, 0 answered
  1. fregas baratis
    fregas baratis avatar
    185 posts
    Registered:
    14 Nov 2002
    16 Jun 2007
    Link to this post
    I have been able to implement complex properties in my controls using this post as an example:
    http://sitefinity.wordpress.com/2007/05/25/working-with-complex-properties-in-custom-public-controls-webtypeeditor/

    This works great for simple things like strings or guids.  Lots of improvement here over the betas.  However, is it possible to return a non-simple value in your selector such as an object, array or collection?  I want the user to be able to select mutiple ID values from a checkbox list in my control when they add it to the page.

    Thanks,
    Craig
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    18 Jun 2007
    Link to this post
    Hello fregas,

    Yes, it is possible that your selector returns an array or collection. For example, in List public control it returns an array of Guid objects.
    You should implement your own selector, inheriting WebUITypeEditor<Guid[]> (in this case the return value will be an array of Guid objects) and the property for the selected identifiers should look as follows:

    public override Guid[] Value
            {
                get
                {
                    return this.selectedIds.ToArray();
                }
                set
                {
                    this.selectedIds = new List<Guid>(value);
                }
            }
    }


    Hope this information helps.

    Regards,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. fregas baratis
    fregas baratis avatar
    185 posts
    Registered:
    14 Nov 2002
    18 Jun 2007
    Link to this post
    i tried this, making one of the properties of a user control a string array just as a test, and also making the string array in the selector, but the property just doesn't show up now.

    Thanks,
    Craig
  4. fregas baratis
    fregas baratis avatar
    185 posts
    Registered:
    14 Nov 2002
    18 Jun 2007
    Link to this post
    I think i figured out the problem.

    Previously, i had a property called "category" for this control which was a string.  WHen I changed that property to hold a string array, its like Sitefinity tried to set the property, failed to do so because its no longer a plain string, and then just decided not to show the property any more.  However, when I changed the property name to "MyCategories" it showed up and let me use my custom selector to populate the array, just like your example.  So i think when there's data for that property already in sitefinity and the developer (me) changes the property's type in the custom user control, it errors and sitefinity just swallows the exception.

    Can you confirm this?  Is there a way to clear out old property data for a control? 

    Also, is there a way to make the property where they have to hit the select button and can't type something in?

    Thanks,
    Craig
  5. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    19 Jun 2007
    Link to this post
    Hi fregas baratis,

    When changing the type of a control property from string to string array, you should be able to see that property afterwards. Perhaps the disappearing is caused by something else or I am missing something here.

    Clearing the invalid control properties is not an easy job for the time being. If you encounter any major issues with them, please let us know and we will send you a db script to clear the unnecessary information.

    For the properties which have web editors, I can suggest two ways to achieve better usability.
     
    The first one is to allow the field to be editable and create proper TypeConverter. The type converter is assigned to control via attribute. You could take a closer look at the attachment to see how you could implement type converter. This scenario is very useful for properties of array types as I think is your case. In the attachment you will find three files each containing a class for web control, type converter and web editor. The code is taken from the Lists module.

    The second scenario is to create the property read only. This way the text box will not be editable and you could fill the property information from the web editor. This scenario is a bit complicated to implement and in case you need it, give us a sign and we'll provide you with the sample code.

    All the best,
    Vassil Daskalov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Chad
    Chad avatar
    1 posts
    Registered:
    27 Sep 2007
    14 Mar 2008
    Link to this post
    I would like to create one of the complex properties as read only(You mentioned it in your second scenario).  Do you have a sample project that accomplishes the read only functionality?

    Thanks,
    Chad
  7. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    18 Mar 2008
    Link to this post
    Hello Chad,

    We don't have a demo with this functionality and also don't support such option. Still, there is something you could do - you could create your control with setting up a Control Designer for it. Please refer to Control Designers for more information, and especially the section Building a Designer for Custom Controls.

    Don't hesitate to contact us if you need any further assistance.

    Regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
7 posts, 0 answered