Get Module by Module ID in DotNetNuke

When building [DotNetNuke] modules, a number of times I've run up against the issue of trying to instantiate a ModuleInfo instance with only a module ID.  However, the GetModule signature on ModuleController takes both a module ID and a tab ID.  In this latest instance where I've come against this issue, I was actually trying to get a tab ID based on the module ID, so I obviously didn't already have one to provide. 

As I started to move down the road of writing my own query to get this simple thing done, I found that the GetModule method and underlying query will take a "null" value for the tab ID!  Unbeknownst to me, the solution was right in front of me, right where I expected it to be the whole time, I just couldn't see it.

So, if you need a ModuleInfo instance and you only have a module ID, call GetModule(moduleId, Null.NullInteger) and you're good to go!

(I've put in a request with the people in charge to add an overload to GetModule so that this is more obvious going forward)

10 Comments

  • I've ran into this in many of the methods and wouldn't find out until I found an example using the "NULL" in the DNN source. VERY ANNOYING!

    Hopefully you can get them to change it, or have an alternative method that takes a nullable param, or leave the param off.

  • Nice find! Thanks for sharing, and submitting to Gemini.

  • Helpfull blog...

  • That's great! Thanks for the info. You've saved my day :D

  • how i know module id
    becuase i create new module but i cann't excut it

  • Hi guys...

    In a page put 2 same modules and every time a module is loaded in the page i want to create a directory based on the moduleId... can anybody help me out

    thanks
    j

  • J,

    I'm not really sure of what you're asking. If you could post some more details about what you're wanting, maybe someone on the DotNetNuke forums will be able to help you.

    Hope that helps,
    Brian Dukes

  • OK I have a Polls Module. I want to Embed that One on a page.

    As soon as i embed that on the page... An Automatic script should run which should create a folder in DesktopModules with a name "Feed+Moduleid"

    for example Module id is 380 then the name of the folder should be feed380


    thanks
    J

  • Assuming that you own that module, you could place some code in the main control of that module to check if the folder already exists, and create it if not.

    Other than that, I don't know of any generic way to run code when a module is placed on the page. What are you trying to accomplish by creating these folders?

  • Hi,

    I'm trying to add settings for my module after checking if it's already available or not (to update if it's available). But when i call ModuleId for the second time (to add the new settings), the ModuleId becomes null!!! how can i make the ModuleId persistent in my module?

    thank you.

Comments have been disabled for this content.