DotNetNuke Modules – Module Settings

ppl-body-02 Since each instance of a module that we put on a page should be able to have it’s own configuration information, it is necessary to have some place that will allow us to configure it.

For example, you may have a module which could display itself in a number of different ways.  You need some way to set this and the settings ASCX file and the associated codebehind file is the place to do this.

<

When we first created our sample module, an associated settings file was created along with it.  You’ll want to open that up now.

< vent Wireup
The settings module is just another user control that shows up in the settings page.  What makes it a little different is that it has two events that fire to tell the module to load and save the settings.

The reason for this is that the save button (it’s actually a link) is not a part of this module.  So if you were relying on the save link to fire and save the contents of this form, you’d either confuse the user by having two save mechanisms on the settings page, or you’d never see the event.

The other thing that’s a little odd is that the information on this page is not typically saved to tables specific to the module.  Instead they are saved into the DotNetNuke settings table.  But you don’t need to worry about that because you’ll be using DotNetNuke-supplied APIs.

When the settings module was created, it should have created two methods:

n style="color: blue;">public override void LoadSettings()
{
}

and

public override void UpdateSettings()
{
}

We will start our work with UpdateSettings() since we have to save data before it makes any sense to retrieve it.

There are two separate API calls for save settings data.  Each looks very similar to the other, but they each do distinctly different things.

< aving Data
For each of these calls, you will need to create an instance of the ModuleController object, so we should make that the first line in our UpdateSettings method:

DotNetNuke.Entities.Modules.ModuleController objModules =
    new DotNetNuke.Entities.Modules.ModuleController();

Once we have that we call either

objModules.UpdateTabModuleSetting
    (TabModuleId, "key", "Value");

or

objModules.UpdateModuleSetting
    (ModuleId, "key", "value");

UpdateModuleSetting() saves configuration information that is common to every instance of the module regardless of what page it shows up on and how many are currently on the page.  Think of it as global settings for this module wherever it shows up.

UpdateTabModuleSetting() saves configuration information that is specific to this module on this page, and if there are multiple instances of the module on the page, this is specific to the specific module on the page.

The first parameter is either the TabModuleId or the ModuleId which are both properties of the settings module and the view module.  So you can just put them in as shown above.

The second parameter is a key value that we will use to look up this information later.  I’ve found that it works best to use the ID of the control on the ASCX file that I’m using to collect the information that I’m saving with these modules as the key.  This makes it easy to correlate the two when you are maintaining the code later.

ything is a String
The value you save is always a string representation of the data that needs to be saved.  So if you need to save a number or a boolean value, you’ll want to convert it to a string using ToString() first.  Keep in mind that when you retrieve the information, you’ll need to convert it back to a number or a boolean.

That’s really all there is to it.  Once you understand what those two methods do, the actual implementation is pretty easy.

On Wednesday, we’ll take a look at the other side of this: Retrieving the information.

 

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 – Retrieving SettingsDotNetNuke Modules – Retrieving Settings On Monday we discussed how to save setting information for our modules.  Today we want to pick back up where we left off and deal with retrieving that information, both in the LoadSettings() metho...
  • DotNetNuke Modules – LinkButtonsDotNetNuke Modules – LinkButtons As you can probably already guess, localizing a LinkButton in DotNetNuke is pretty straightforward. But you'll never guess what most people miss when they add this little control to their DotNetNuk...
  • DotNetNuke Modules – PortalModuleBaseDotNetNuke Modules – PortalModuleBase We've been through most of the basics now with respect to creating the View module of the DotNetNuke module set.  We will be moving on to the Settings module next.  But before we do, we need to re...
  • DotNetNuke Modules – Internationalization (part 2)DotNetNuke Modules – Internationalization (part 2) Last Thursday, we looked at how you could change the text of the modules in DotNetNuke.  Today, we want to show you how to add that same capability to your own modules. When you created your...