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

  • DotNetNuke Modules – Creating Base ModulesDotNetNuke Modules – Creating Base Modules Now that we have DotNetNuke installed into Visual Studio we can go ahead and create our first modules. Actually, creating the modules is pretty simple. But it is even easier to do it wrong, which...
  • DotNetNuke Modules – Making Content PortableDotNetNuke Modules – Making Content Portable The last main feature of module development that we need to discuss is the implementation of IPortable. If you've ever worked with other content management systems in a corporate environment, y...
  • DotNetNuke Modules – Labels w/ no HelpDotNetNuke Modules – Labels w/ no Help While the bulk of the labels you use on a module will be DotNetNuke labels, occasionally you want to be able to put text on the screen that doesn't need context help and doesn't need to be associat...
  • DotNetNuke – Modules – Linking within the moduleDotNetNuke – Modules – Linking within the module Now that we have the module skeleton up and running and we have a data access layer, the next thing we need to look at is specific functions you may need to use from within your code. One of the m...
  • DotNetNuke – Modules – Portal Specific ModulesDotNetNuke – Modules – Portal Specific Modules Many of you won't care too much about creating Portal Specific Modules because you'll be creating modules for an environment that only has one portal. However, if you are creating a module for res...
  • http://nes.nesinteractivos.com Néstor Sánchez

    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.