More in this section

Forums / Developing with Sitefinity / Assign ItemsParentId from encapsulated control

Assign ItemsParentId from encapsulated control

4 posts, 0 answered
  1. Gary
    Gary avatar
    91 posts
    Registered:
    19 Jul 2007
    23 Mar 2013
    Link to this post
    I have added the DownloadListView to a user control, because I need a way to use this control wherein the selected library is set dynamically.

    I had hoped to simply put the following code in either the Page_Load or Page_PreRender handlers of the code behind:

    downloadListView.MasterViewDefinition.ItemsParentId = DynamicallyDetermineParentId();

    However, the assignment seems to be ignored. 

    Attempting to analyze the source code makes me think that the MasterViewDefinition is loaded and processed from within CreateChildControls.  If that is the case, then I would never have an opportunity to override a property in the MasterViewDefinition. I then presume that the only way to make this work is to sub-class DownloadListView, override CreateChildControls, re-implement the method body with the same source code of the original, with the addition of setting the above mentioned property before calling this.LoadView(viewName).

    Is that the only way to solve this problem?

    Thanks,
    Gary
  2. Patrick Dunn
    Patrick Dunn avatar
    237 posts
    Registered:
    03 Nov 2014
    27 Mar 2013
    Link to this post
    Hi Gary,

    Yes. Your assumptions are correct. However, it might just be wholly easier to use our API to just create your own widget at that point. The DownloadList isn't incredibly complex if you need just one or two views and it will give you more control over everything.

    Getting all documents is as easy as:

    public static IQueryable<Document> GetDocumentsByDocumentLibraryFluentAPI(Guid documentLibraryId)
    {
        return App.WorkWith().DocumentLibrary(documentLibraryId).Documents().Where(d => d.Status == ContentLifecycleStatus.Live).Get();
    }

    Add to the .Where() filter and you'll be able to just filter by library dynamically. You can then just bind it to a grid/listview and get the same result with more control than the document list view widget. You can create a designer in a few clicks with Thunder to sort the library.

    Kind regards,
    Patrick Dunn
    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. Gary
    Gary avatar
    91 posts
    Registered:
    19 Jul 2007
    28 Mar 2013 in reply to Patrick Dunn
    Link to this post
    Thank you, Patrick. I came to the same conclusion, although I implemented it as a straightforward user control. Your approach to create a Sitefinity "Widget" instead of a user control is interesting. Is the advantage of this approach, that I  would have been the ability to create a custom designer and also apply different rendering templates?

    Regards,
    Gary
  4. Patrick Dunn
    Patrick Dunn avatar
    237 posts
    Registered:
    03 Nov 2014
    29 Mar 2013
    Link to this post
    Hi Gary,

     A Sitefinity widget is essentially a user or custom control that gets registered in the toolbox. The benefit of a widget over just using it as a typically control is that you do get the designer which would allow you to implement specific configurations, change them on the fly, etc. If you build your widget as an ASP.NET custom control then you can take advantage of setting different templates. Here's the documentation.

    I hope this helps.

    All the best,
    Patrick Dunn
    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
4 posts, 0 answered