DotNetNuke

Ask Nik: Getting the ModuleId of a module from its container

March 13, 2005

author:

Ask Nik: Getting the ModuleId of a module from its container

nokiko asks:

I am working on some new containers and dnn enhancements. I want to know in my container which moduleid is loaded so lets say i have an ascx container and in there i have the following:

rest of container …

Is there a function or another way that in an ascx container I would know which moduleid is loaded in there.

So that way lets say i have 2 modules one one page and i want the ascx container to render

content here
content here

i would need this to imge replace techniques on my h3 tags for instance

#mod_36 h3 { background:url(announcements.gif) }
#mod_37 h3 { background:url(events.gif)}

Nik’s answer:

That’s an excellent question nokiko. In DotNetNuke 3.x, the Container class has a public, static method called GetPortalModuleBase(). This method requires one parameter — a usercontrol that is present in the container. With this knowledge, it is easy to figure out a solution. For example, most of the default DNN containers have a title defined using: . In any of these containers, you can add the following line to display the ModuleId of the module present in the container:

<%= DotNetNuke.UI.Containers.Container.GetPortalModuleBase(dnnTitle).ModuleId.ToString() %>

You can also use the same technique to display any other Portal, Tab, Module or User property to customize the appearance of containers dynamically:

<%= DotNetNuke.UI.Containers.Container.GetPortalModuleBase(dnnTitle).PortalSettings.PortalName %>
<%= DotNetNuke.UI.Containers.Container.GetPortalModuleBase(dnnTitle).PortalSettings.ActiveTab.TabName %>
<%= DotNetNuke.UI.Containers.Container.GetPortalModuleBase(dnnTitle).ModuleConfiguration.ModuleTitle %>
<%= DotNetNuke.UI.Containers.Container.GetPortalModuleBase(dnnTitle).UserInfo.FirstName %>

If you don’t have a need for the DNN Title control in your container, that’s OK. You can add it anyway with an attribute of “Visible=false”. It is possible to achieve this result without using any skin control, however it requires a little more code and is not worth the effort in most situations.

 

Founder NftyDreams; founder Decentology; co-founder DNN Software; educator; Open Source proponent; Microsoft MVP; tech geek; creative thinker; husband; dad. Personal blog: http://www.kalyani.com. Twitter: @techbubble
Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.