Try Now
More in this section

Forums / Module Builder / Retrieve dynamic module content from its parent page

Retrieve dynamic module content from its parent page

1 posts, 0 answered
  1. Nate
    Nate avatar
    7 posts
    31 Jul 2013
    19 Aug 2013
    Link to this post
    I'm trying to find a way to retrieve a dynamic module I've created from the page to which I added it.  I can't figure out how to get the page itself to tell me about any dynamic modules it may have, nor can I figure out how to have the module itself tell me which page is its parent.

    I'm using the PageManager to retrieve the page, and I know I can use the DynamicModuleManager to retrieve the modules by type, but how do I find that relationship in code?

    Edit: I should probably have mentioned that I have a custom MVC widget that I created to display my module data.  I did manage to find a way to accomplish this, but I'd be happy to hear any alternative solutions.

    My code looks something like this:
    PageManager pm = PageManager.GetManager();
    PageNode videoParent = pm.GetPageNode(pageID);
    DynamicModuleManager dmm = DynamicModuleManager.GetManager();
    Type videoType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.VideoLibrary.Video");
    if (videoParent.Page.Controls != null && videoParent.Page.Controls.Count > 0)
        //this is making the assumption that I have one and only one MVC video widget on the page
        List<PageControl> videoControls = videoParent.Page.Controls.Where(ctrl => ctrl.ObjectType == "Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy").ToList();
        if (videoControls.Count == 1)
            Control c = pm.LoadControl(videoControls.First());  //convert the control into a System.Web.UI Control
            //as a Control, it doesn't have the properties on it I needed, but it could be converted to a MvcControllerProxy, which did have the data on it
            string id = ((MvcControllerProxy)c).Settings.Values["VideoID"] as string;  //Settings is dynamically generated, so you need to inspect the Values property to see what's there
            Guid videoID = new Guid(id);
            Telerik.Sitefinity.DynamicModules.Model.DynamicContent videoContent = dmm.GetDataItem(videoType, videoID);
            //do stuff with the videoContent object
1 posts, 0 answered