DotNetNuke Modules – Finding The Page a Module is On

land-0127 Last week we talked a bit about Inter Module Communication, the ability of one module to notify another module on the page that something needs to happen without requiring a post back.  The other need you may have is something I refer to as Cross Page Communication.  This is not a dotnetnuke term, I just made it up today.

Here’s the problem.  In some cases, you may have a module that you’ve placed on a page that should only ever be on one page.  In my case, this was the checkout module.  I needed some way of retrieving the page that that module was on so that I could create a hyperlink to that page from my modules that displayed my products and my “mini cart” module that displayed a summary of items in the shopping cart.

Here’s how I did it:

// Find the tab the module specified by
//friendlyName, is on.

// ModuleController is in:
// dotnetnuke.Entities.Modules namespace
ModuleController moduleController =
    new ModuleController();

// User the friendlyName to find the moduleID
int myModuleDefId =
    Globals.GetDesktopModuleByName(friendlyName)
        .DesktopModuleID;

// Get all the tabs available for this portal.
ArrayList tabs = (new TabController())
    .GetTabs(portalId);
foreach (TabInfo ti in tabs)
{
    // For each page, find all the modules on the page
    Dictionary<int,ModuleInfo> modules =
        moduleController.GetTabModules( ti.TabID);
    foreach (ModuleInfo mi in modules.Values)
    {
        // If the module on the page is the module we
        // are looking for, return it.
        if (mi.DesktopModuleID == myModuleDefId)
        {
            return ti.TabID;
        }
    }
}

 

Other post in DotNetNuke - Module Development

Related Post

5 Responses to “DotNetNuke Modules – Finding The Page a Module is On”

  • The tab iteration on a portal with thousands of pages will be quite expensive. A better solution from an architectural point is that the Checkout module saves its location to the DB, either by way of a module setting or a specific field in a module configuration table. In that manner, your other modules can retrieve this directly.

  • Dave:

    Yes, it is (was).

    As is common with most of my post I only gave you the specifics on how to retrieve the information. I did not tell you what to do with it.

    IF you need to find out where a module is, this is how you do it. And even if you use this method, you wouldn’t retrieve it every time you hit the page because even on a relatively small site, you’d get killed on performance.

  • Ant:

    Will it be better if we do this?

    Dim objModuleController As DotNetNuke.Entities.Modules.ModuleController = New ModuleController()
    Dim moduleList As ArrayList = objModuleController.GetModulesByDefinition(PortalId, moduleName)
    For Each modInfo As ModuleInfo In moduleList
    ‘Return modInfo.TabID
    Next

  • Ant:

    Private Function GetFirstModuleTabId(ByVal PortalId As Integer, ByVal moduleName As String) As Integer
    Dim objModuleController As DotNetNuke.Entities.Modules.ModuleController = New ModuleController()
    Dim moduleList As ArrayList = objModuleController.GetModulesByDefinition(PortalId, moduleName)

    For Each modInfo As ModuleInfo In moduleList
    Return modInfo.TabID
    Next
    Return 0
    End Function

  • Dave:

    Without running I’d have to say no only because it looks like really old syntax if it worked at all.