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

Forums / Developing with Sitefinity / How can I override the property FilterExpression for customized DownloadList?

How can I override the property FilterExpression for customized DownloadList?

7 posts, 0 answered
  1. Tom
    Tom avatar
    19 posts
    Registered:
    15 Sep 2009
    03 Aug 2011
    Link to this post
    Hi there

    I try to override the setter of the DownloadList so that there is a default list chosen instead of all items! (Having several 100 of documents and all of them displayed when adding the control is really a pain...)

    Unfortunatelly there are some very strange behaviours when changing the list I want to use as source (e.g. deselect "EmptyLib" and select "TestLib" instead). All of a sudden there are several "TestLib" and "EmptyList" items I can choose from (not physically, only in choice box).

    Any Ideas?

    using System;
    using System.ComponentModel;
    using System.Globalization;
     
    using Telerik.Libraries;
    using Telerik.Web;
     
    namespace BPUK.CorporateInternet.Utilities.WebControls
    {
        public class CustomDownloadListToolboxItem : ToolboxItem
        {
            public CustomDownloadListToolboxItem()
                : base(typeof(ExtendedDownloadList))
            {
                base.DisplayName = "DownloadList";
                base.Description = "Provides a list of items selected from a library";
            }
        }
     
        [ToolboxItem(typeof(CustomDownloadListToolboxItem))]
        public class ExtendedDownloadList : DownloadList
        {
            protected const string EmptyDocumentLibraryName = "EmptyDocumentLibrary";
     
            public override string ItemListTemplatePath
            {
                get
                {
                    return "~/Custom/Sitefinity/ControlTemplates/Libraries/DownloadList.ascx";
                }
            }
     
            public override bool AllowPaging
            {
                get
                {
                    return false;
                }
            }
     
            public new DownloadListDisplayMode Mode
            {
                get
                {
                    return DownloadListDisplayMode.TableMode;
                }
            }
     
            public override string FilterExpression
            {
                get
                {
                    string expression = base.FilterExpression;
     
                    if (expression.Equals(string.Empty))
                    {
                        var libraryManager = new LibraryManager();
                        var library = libraryManager.GetLibrary(EmptyDocumentLibraryName);
                        expression = string.Format(CultureInfo.InvariantCulture, "ParentID IN ({0})", library.ID);
                    }
     
                    return expression;
                }
            }
        }
    }
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Aug 2011
    Link to this post
    Hi Tom,

    The datasource is populated based on the filter. Could you check what is the FilterExpression value and whether it contains the proper ParentID values?
    If you use page caching, remove it and see whether there would be a difference.

    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. Tom
    Tom avatar
    19 posts
    Registered:
    15 Sep 2009
    04 Aug 2011
    Link to this post
    Hi Ivan

    The point is, if I try to manipulate the FilterExpression inside the overriden property getter, things start to mess up. Not if I just pass through the value.

    public override string FilterExpression
    {
        get
        {
            string expression = base.FilterExpression;
            return expression;
        }
    }

    So the problem is when manipulating the value in the getter (which is strange because that is what you do as well)...
    There are also quite a lot of calls to the property getter when setting a value.

    Regards,
    Tom
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Aug 2011
    Link to this post
    Hi Tom,

    Yes, but we get the value from the ViewState

    object obj = ViewState["FilterExpression"];
                    if (obj != null)
                        return (string)obj;
      return string.Empty; 

    Best wishes,
    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
  5. Tom
    Tom avatar
    19 posts
    Registered:
    15 Sep 2009
    04 Aug 2011
    Link to this post
    Is it possible that you try to check my code in a test environment? I'm quite sure that there is an issue with manipulating the property by code...
  6. Tom
    Tom avatar
    19 posts
    Registered:
    15 Sep 2009
    12 Aug 2011
    Link to this post
    Caching was and still is disabled on page!

    ViewState is enabled! (If disabled, the control won't work anymore due to it's usage of the ViewState value)
  7. Tom
    Tom avatar
    19 posts
    Registered:
    15 Sep 2009
    12 Aug 2011
    Link to this post
    I checked the various FilterExpressions when using my overridden property (see code above).

    Empty library has Guid: 2fc9879c-75a5-4097-ac8b-6eb7aeda586c
    Test library has Guid: a57e10ce-7497-4689-97a3-969837d79f6a

    Initial: ParentID IN (2fc9879c-75a5-4097-ac8b-6eb7aeda586c)

    When not changing the selection, the FilterExpression remains the same as before...

    Selecting all items from any library option: ParentID IN (2fc9879c-75a5-4097-ac8b-6eb7aeda586c) => instead of empty

    From here on, every Guid creates a list item in the library selection list (creates a lot of redundant entries)!!!

    Selecting additional library: ParentID IN (2fc9879c-75a5-4097-ac8b-6eb7aeda586c) AND ParentID IN (a57e10ce-7497-4689-97a3-969837d79f6a, 2fc9879c-75a5-4097-ac8b-6eb7aeda586c) => instead of ParentID IN (a57e10ce-7497-4689-97a3-969837d79f6a, 2fc9879c-75a5-4097-ac8b-6eb7aeda586c)

    Selecting different library: ParentID IN (2fc9879c-75a5-4097-ac8b-6eb7aeda586c) AND ParentID IN (a57e10ce-7497-4689-97a3-969837d79f6a) => instead of ParentID IN (a57e10ce-7497-4689-97a3-969837d79f6a)

    This has probably to do with the way you calculate the filter expressione by clearing and resetting the expression instead of updating (as I mentioned before, a lot of access to the getter and setter of FilterExpression)?

    This issue is urgent, so please check the code!!!

Register for webinar
7 posts, 0 answered