Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to get the ModuleId from another ModuleHow to get the ModuleId from another Module
Previous
 
Next
New Post
11/27/2007 9:34 PM
 

Actually that does not quite get you the desired ModuleID, only the DesktopModuleID which has a whole different purpose.  Here are several points to keep in mind when getting information about a module:

1. A module definition's FriendlyName can be changed on the Host-->ModuleDefinitions page. Several DNN versions back, a new module defintion property was added, the ModuleName. This is not supposed to change - and, in fact, recent DNN versions dis-able this the text box for ModuleName on the ModuleDefinitions page.  So, it is much safer to search for a module definition based on ModuleName rather than FriendlyName.  The DesktopModuleController now provides the following method:

Function GetDesktopModuleByModuleName(ByVal ModuleName As String) As DesktopModuleInfo

The method which you used indirectly calls GetDesktopModuleByFriendlyName which uses the FriendlyName rather than ModuleName for its search.

2. For a given PortalID, there can be one or many module instances all having the same FriendlyName or ModuleName located on one or many pages (tabs).  Think how many times the core Html/Text module appears on a page or portal.

3. Multiple occurances of modules having the same FriendlyName or ModuleName may have different ModuleID's (when placed with the Add Module command) or with the SAME ModuleID (but diferent TabModuleID's) when placed with the Add Existing Module command.

If I may assume that your requirement is to obtain the ModuleID for the instance of a module which you know occurs once and only once in the Portal then the following will work provided you can trust the FriendlyName not to have changed from its installation:

Function GetModuleID(ByVal TargetModuleFriendlyName As String) As Integer
   Dim mc As New ModuleController
   Dim mi As ModuleInfo = mc.GetModuleByDefinition(PortalId, TargetModuleFriendlyName)
   If mi Is Nothing Then
       Return -1
   Else
       Return mi.ModuleID
   End If
End Function

A better method (and a variation of the one that I actually use which returns multiple matches in a dictionary object with ModuleTitle as Key and ModuleInfo object as Value)  allows you to specify the TabID on which the module instance is located and the ModuleName rather than FriendlyName:

Function GetModuleID(ByVal TargetTabID As Integer, ByVal TargetModuleName As String) As Integer
    Dim dmc As New DesktopModuleController
    Dim dmi As DesktopModuleInfo = dmc.GetDesktopModuleByModuleName(TargetModuleName)
    If Not dmi Is Nothing Then
         Dim mc As New ModuleController
         Dim modList As ArrayList = mc.GetModulesByDefinition(PortalId, dmi.FriendlyName)
         For Each mi As ModuleInfo In modList
               If mi.TabID = TargetTabID Then Return mi.ModuleID
         Next
    End If
    Return -1
End Function

Note that this last method could still return only the first of potentially multiple matches with the same TabID and ModuleID but different TabModuleID's.


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
11/28/2007 12:04 PM
 

I have more functions for similar cases. One is recursive and search modules on page by module header text and some others.

In your case is much more simple to query database. All is there and data are well structured so is easy to get id.

Kind regards,

Primoz

 
New Post
11/28/2007 3:22 PM
 

Thank you for your posts guys.

I'm still wondering where to get detailed explaination to understand what's is the difference between Module and Tab ?

 

In any way, I understand that both solutions (helper class and direct query) are workaround to implement missing features in the framework.

To develop robust application, not only content management, but for instance in my case a tool to manage a school, some efforts should still be done to provide helpers in the communication between modules, controls...

In any case DNN is really promising, I like it.

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to get the ModuleId from another ModuleHow to get the ModuleId from another Module


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out