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

Forums / Developing with Sitefinity / Adding a custom TextSetting to a control (DownloadList)

Adding a custom TextSetting to a control (DownloadList)

12 posts, 1 answered
  1. Lucas
    Lucas avatar
    65 posts
    Registered:
    22 Mar 2010
    07 Jun 2010
    Link to this post
    Hi,

    I'm trying to add a custom boolean to the Library's DownloadList. I have successfully created my ascx, and the related css classes (thanks to the blog), but I'm stuck when I want to add a new TextSetting to my designer:

    I'm adding
    <sf:TextSetting ID="TextSetting17"
                              TargetID="CssExtension"
                              SettingTitle="Use a custom icon for each extension"
                              AllowLabelSetting="False"
                              AllowFormatSetting="False"
                              AllowVisibilitySetting="True"
                              TargetVisibleByDefault="True" />
    to the ascx, the new checkbox appears as expected, but I can't find how to reuse this value in my control. I see that the "this.MasterSettings" collection contains the original settings (Title, Author, ...), but no trace of my CssExtention setting.

    What am I doing wrong?

    Additional question: is there a easy way (eg, without defining a new SettingService) to add a "free text" setting to the designer?

    Thanks a lot!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Jun 2010
    Link to this post
    Hi Lucas,

    It would not be possible to access the text setting you have created from the control. The relation is PresetationMode- Control, but not Control- Presentation mode. All control properties are saved as MasterSettings and DetailsSettings properties in XML format - you can check the Advanced tab of the control. The options are

    1. Parse the MasterSettings and DetailSettings xml and get the data from there
    2. Use public property instead.
    3. Use a simple control in the ControlDesigner that is outside of the presentation modes.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
  3. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    30 Jul 2010
    Link to this post
    Hi Ivan,

    I'm experiencing some very similar challenges and am missing something in the answer here. I'm wondering if you can help me out. I have added a new TextSetting to my DownloadListControlDesigner.asxc file, specifically a "PublishedDate" field. Now in my presentation mode user control for TableView, on page load I want to hide the table cells based on what the DownloadList settings are for Author, Description, Extension and my custom option PublishDate. You mention a couple options but for example in option 1. Parse the MasterSettings and DetailSettings xml and get the data from there, I know how to parse xml data to get what I need, but I can't figure out how to get the actual xml data on page load of the user control. Is this possible? Any samples/direction?

    As always, any help is greatly appreciated!
    Regards,
    Phill
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    30 Jul 2010
    Link to this post
    Hello Phill Hodgkinson,

    The control has MasterSettings and DetailSettings properties that you can access and read. You should better create a public properties of boolean type ( show /hide) and and set them, because parsing the XML will requires some more work, since you can easily read these public properties inside SetItemMetadata and change the visibility of the controls in your template.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    03 Aug 2010
    Link to this post
    Hi Ivan,
    Even though this is proving to be a challenge to me, my goal here is to make it easier for the end user that will be using the CMS. So with this in mind, it doesn't make sense that they check a box to show/hide author, description, uploaded date, but then have to go somewhere else to check a box to show my custom option PublishedDate. I want to continue with having the settings all in one place. When DownloadListControlDesigner.ascx loads it's Table or List template (usercontrol) it knows what options are checked/not checked, so there must be a way from the user control (on page load, pre render?) to access these settings? Can you suggest any other options that would allow me to keep the DownloadListControlDesigner.ascx working as it is in a consistent manner and then how to access the settings from the user control?

    Again, thanks for your help.

    Regards,
    Phill
  6. Lucas
    Lucas avatar
    65 posts
    Registered:
    22 Mar 2010
    04 Aug 2010
    Link to this post
    Hi Phill,

    I personally encountered the same kind of issue, and I think I'm going to redo the configuration screen from scratch.

    I think the wizard is unfortunately too hard to tweak to be usable.
  7. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    04 Aug 2010
    Link to this post
    That's a real shame, as the wizard screen gets updated with my new setting automatically, I didn't have to change anything there at all. I just want to be able to access the settings from the user control and since the built in settings get applied when the user control is loaded I figured there has to be some way to do it. Still hoping Ivan will come through for me as he has so often in the past ;)

    I'd be curious as to what kind of solution you come up with in the end though.

    Regards,
    Phill
  8. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Aug 2010
    Link to this post
    Hello Phill Hodgkinson,

    To achieve this a custom control designer has to be implemented. Here I do not mean just modifying the control's template. You also need to create a control which derives from DownloadList and expose your properties there. Here is stub code for the designer:
    using Telerik.Libraries.WebControls.Design;
    using Telerik.Libraries;
     
    /// <summary>
    /// Summary description for CustomDownloadListControlDesigner
    /// </summary>
    public class CustomDownloadListControlDesigner:DownloadListDesigner
    {
        public override string DesignerTemplatePath
        {
            get
            {
                return "";
            }
            set
            {
                base.DesignerTemplatePath = value;
            }
        }
     
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            //get a referene of the designed control. In this case it would be your custom download list
            DownloadList downloadList = (DownloadList)DesignedControl;
            //then you must read the values of your custom properties and pass them to the cotnrols which are going to visualise them in your desinger template
            //you need to subscribe to the value changed event of the controls in your designer template
            //then in this event you will get the new value and pass it to the DesignedControl's respective property
        }
        public override void OnSaving()
        {
            base.OnSaving();
            //on saving event is also suitable for passing the property changes to the designed control
        }
    }

    More information on creating control designers can be found here. After you have created the control designer you need to set the control designer attribute of your custom download list control:
    [ControlDesignerAttribute("CustomDownloadListControlDesigner, YourAssemblyName")]
    public class CustomDownloadList: DownloadList


    Kind regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    05 Aug 2010
    Link to this post
    Hi Radoslav,

    Thanks for your post. When attempting something based on what you recommend, actually exactly like you recommend, I didn't modify any thing other than setting the value for the DesignerTemplatePath to my custom template I get the following error:

    Value cannot be null.
    Parameter name: viewName


    I really don't want to both you guys ever single step of the way so could you help me out and point me to the documentation for creating a custom DownloadList Designer? I even promise to share my working solution to help others in the future with the seemingly simple yet frustrating task.

    Thanks in advance,
    Phill
  10. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Aug 2010
    Link to this post
    Hello Phill Hodgkinson,

    I am sorry I have not been clear enough. Have you set the template path to the one of your custom designer?
    public override string DesignerTemplatePath
    {
        get
        {
            return "~/YourPathToTheControlTemplate";
        }
        set
        {
            base.DesignerTemplatePath = value;
        }
    }

    Also, I have linked articles on creating control designers in my previous post.

    Kind regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    05 Aug 2010
    Link to this post
    Yes, that's the one thing I changed from your sample. I changed it to the same ascx file that I had orginally mapped in the ControlsConfig.xml file. The control I'm adding to the page is added in the web.config under <toolboxControls> as
    <add name="Doc List" section="Custom Content" type="Telerik.Libraries.WebControls.CustomDownloadListDesigner, App_Code" description="Custom display list"/>

    If this isn't the proper way to add it, how would I add it? I tried using the ControlsConfig.xml file again but when I chagned it to Telerik.Libraries.WebControls.CustomDownloadListDesigner, App_Code it just loaded the original built in designer.

    For reference, here's the complete error I get:
    Value cannot be null.
    Parameter name: viewName
     
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
     
    Exception Details: System.ArgumentNullException: Value cannot be null.
    Parameter name: viewName
     
    Source Error:
     
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
     
    Stack Trace:
     
     
    [ArgumentNullException: Value cannot be null.
    Parameter name: viewName]
       Telerik.Cms.Web.UI.ViewModeControl`1.GetViewType(String viewName) +332
       Telerik.Cms.Web.UI.ViewModeControl`1.get_ViewModeType() +31
     
    [TargetInvocationException: Property accessor 'ViewModeType' on object 'PBNJ.Libraries.WebControls.CustomDownloadListDesigner' threw the following exception:'Value cannot be null.
    Parameter name: viewName']
       System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component) +7137128
       Telerik.Cms.Web.UI.PropertyView.CreateChildControls() +2314
       System.Web.UI.Control.EnsureChildControls() +146
       System.Web.UI.Control.PreRenderRecursiveInternal() +61
       System.Web.UI.Control.PreRenderRecursiveInternal() +224
       System.Web.UI.Control.PreRenderRecursiveInternal() +224
       System.Web.UI.Control.PreRenderRecursiveInternal() +224
       System.Web.UI.Control.PreRenderRecursiveInternal() +224
       System.Web.UI.Control.PreRenderRecursiveInternal() +224
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394
     
    Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927
    I did take a look at the link you provided but I'm finding that all samples seem to be related to Blogs/News/Events which are based on the ContentViewDesigner and not the DownloadListDesigner. There seem to be some differences here in how they are implemented, or I'm missing something obvious.

    Thanks again,
    Phill
  12. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Aug 2010
    Link to this post
    Hi Phill Hodgkinson,

    Please go back to my first post. You should create a custom download list control and set its control designer attribute. You should not add the download list control designer to the toolbox. I have attached sample code to start you going. You need to add the custom download list control to the toolbox.

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
12 posts, 1 answered