0
votes

I have created a dotnetnuke module, it has multiple controls wrapped in a single module

Now i want to access the settings variable across module, say for example i have a setting for dateformat, now the dateformat user selects should be used throughout moduleIt works fine with the view control which comes by default with Dotnetnuke (ChrisToc Template)But when i add new control it does not works, i also added proper inherits, it never throws compile error (in case it does not gets proper namespace) Below is the code i am using:
public partial class ViewEntry : WireModuleBase
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("SETTINGS: " + Settings["WireDateFormat"]);
        }
    }

Any help will be appreciated

1
I assume all the controls are in the same namespace? - braindice

1 Answers

0
votes

I don't ever use the Setting dictionary in my module views. First, it leaves you open to code errors by having to hardcode the key string when accessing the setting. Second, it makes it hard to share with you business logic or other views. My preferred pattern for settings is to create an interface and class for my settings that provides class attribute for my settings and performs the plumbing calls to DNN core to get and set those settings.

Follow this link to a Codeplex project where you will find a class SettingsRepository and ISettingsRepository interface.

Once you modified the public properties for your settings (ie: WireDateFormat) into the class and interface, you can then use it in your module settings implementation.

Get the setting:

ISettingsRepository settingsCtrl = new SettingsRepository(this.ModuleId, this.TabModuleId);
txtSetting1.Text = settingsCtrl.Setting1;

Write the setting

ISettingsRepository settingsCtrl = new SettingsRepository(this.ModuleId, this.TabModuleId);
settingsCtrl.Setting1 = txtSetting1.Text;

Once the settings is stored (in this case using the TabModuleId, but you can use the ModuleID constructor overload if you want to share the setting across modules on a page), you can use the same "get" code in any of your module views or business logic.