Published on: 28 January, 2018

How to get module setting hash table outside from DNN Module setting?

Tumblr Digg Google Plus

Sometimes when you create your own DNN Modules, you want to get access to Module settings outside of the PortalModuleBase class. By default, by inheriting the PortalModuleBase you can get the module settings easily by using the following code. Let says you have a setting name called HeaderText.

string headerText = "";
if ((string)Settings["HeaderText"] != null)
{
	headerText = (string)Settings["HeaderText"];
}

Note: PortalModuleBase must be inherited when you create a DNN Module. You can read my article about creating your First DNN Module. So how about to retrieve the module settings if you are not inheriting this base class? Well, it is pretty easy. The first thing you have to do is to include the following namespace.

using DotNetNuke.Entities.Modules;

Once you have included the namespace, you can use the following code. Note: in order to use the following code, you have to know what is the module id. Each instance of a module installed in a DNN page, will have their own unique module id.

ModuleController objModuleController = new ModuleController();
ModuleInfo objModule = objModuleController.GetModule(moduleID);
if(objModule != null){
	var moduleSettings = objModuleController.GetTabModuleSettings(objModule.TabModuleID);
	if(moduleSettings != null){
			string headerText = "";
			if ((string)Settings["HeaderText"] != null)
		{
			headerText = (string)Settings["HeaderText"];
		}
	}
}

Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.