0

I am creating a module which will allow me to save HTML content in the settings section of the DNN module which will be stored on the Portal Settings.

How do I ensure my setting is unique only for the current container it is placed on? How can I get the ID of the current div the module is placed on?

Then I would be able to place the module in the exact same place. For example the Header and Footer section of the website.

So, if I can get ParentDivID and then append it at the end of the settings key.

For example: if (dictSettings.ContainsKey("GlobalHTML" + ParentDivID))

This is my current code for the DNN module Settings Codebehind

if (Page.IsPostBack == false)
{
    //Updated to use Portal Settings instead of per page per tab settings
    var dictSettings = m_PortalController.GetPortalSettings(PortalId);

    if (dictSettings.ContainsKey("GlobalHTML"))
    {
     txtGlobalHTML.Text = dictSettings["GlobalHTML"];
    }

}
Tig7r
  • 525
  • 1
  • 4
  • 21
  • I believe each instance of a module has a unique ID. That would be the first thing I would look for. Another thing you could do is have a radio selection for header, footer, ect and then set the settings based on that. – Mickers Feb 12 '19 at 16:24

3 Answers3

2

You normally store store module settings in the ModuleSettings table of the ModuleController.

var modules = new ModuleController();
modules.UpdateTabModuleSetting(TabModuleId, "SettingKey", "SettingValue");

But for HTML I would create a custom table that stores the HTML with a Primary Key and a TabModuleId column.

VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • 1
    This doesn't take multiple portals into consideration. Also the question was how to differentiate between two of the same module on the same page. – Mickers Feb 12 '19 at 17:11
  • 2
    It does not have to. ModuleID's are always unique, even across portals. – VDWWD Feb 12 '19 at 17:14
  • Alright. Been a while since I've worked with DNN I just remembering running into settings issues across portals. – Mickers Feb 12 '19 at 17:46
2

I have figured out a way to add the same module to the page on a particular portal and have the content that is already saved in the settings to be linked with the use of an ID which I can set.

So if I want the same telephone number on multiple pages or footer content, then I can leave the HTML field in the settings section empty and just make the ID the same as the one I have initially configured with HTML content.

This is the code for when the module settings loads:

 if (Page.IsPostBack == false)
 {
  per tab settings
  var dictSettings = m_PortalController.GetPortalSettings(PortalId);

  if (Settings.Contains("GlobalIDHTML"))
  {
  txtIDGlobalHTML.Text = Settings["GlobalIDHTML"].ToString();
  LinkID = Settings["GlobalIDHTML"].ToString();
  }

  if (dictSettings.ContainsKey("GlobalHTML"+ LinkID))
  {
  txtGlobalHTML.Text = dictSettings["GlobalHTML"+ LinkID];                       
  }      
}

This is the code for Updating the settings:

 public override void UpdateSettings()
 {
  try
     {
      var modules = new ModuleController();
      modules.UpdateModuleSetting(ModuleId, "GlobalIDHTML", txtIDGlobalHTML.Text);
      modules.UpdateTabModuleSetting(TabModuleId, "GlobalIDHTML", txtIDGlobalHTML.Text);
      var globalstoragevalue = "GlobalHTML"+ txtIDGlobalHTML.Text;

      if (txtGlobalHTML.Text != null && !string.IsNullOrWhiteSpace(txtGlobalHTML.Text))
      {
      PortalController.UpdatePortalSetting(PortalId, globalstoragevalue, txtGlobalHTML.Text);
      }
    }
    catch (Exception exc) //Module failed to load
    {
     Exceptions.ProcessModuleLoadException(this, exc);
    }
  }

My code when the page loads:

  try
  {
     if (Settings["GlobalIDHTML"] != null && !string.IsNullOrWhiteSpace(Settings["GlobalIDHTML"].ToString()))
    {
    GlobalLinkID = Settings["GlobalIDHTML"].ToString();
    }
    GlobalContent = TryGetPortalSetting("GlobalHTML"+ GlobalLinkID);

    if (GlobalContent != null)
   {
    GlobalPageContent = GlobalContent;
   }                  
  }

The module settings:

enter image description here

The result:

enter image description here

Tig7r
  • 525
  • 1
  • 4
  • 21
0

I would look at how the HTML module does this ...

Joe Craig
  • 1,244
  • 1
  • 7
  • 7