If you’re creating custom modules for DotNetNuke you’ve certainly tried to add your own settings to the settings.ascx in the default module setup.
Creating your settings happens in 5 steps. Where ever you see “settingname” replace with your setting’s name:
1) Add the html to the Settings.ascx file like this (the formatting doesn’t matter; customize to fit your site
<table>
<tr>
<td>
<dnn:Label ID="lblSettingName" runat="server"
ControlName="txtSettingName Suffix=":"></dnn:Label>
</td>
<td>
<asp:TextBox ID="txtEventModuleLink" CssClass="NormalTextBox"
Width="350" runat="server" />
</td>
</tr>
</table>
2) Add code to the Settings.ascx.vb to load the value for the setting into the textbox created in step one. Do not worry that the setting doesn’t actually have a value yet.
Public Overrides Sub LoadSettings()
Try
If (Page.IsPostBack = False) Then
If CType(TabModuleSettings("settingname"), String) _
<> "" Then
txtSettingName.Text = _
CType(TabModuleSettings("settingname"), String)
End If
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
3) Add code to the Settings.ascx.vb to save the value from textbox created in step one.
Public Overrides Sub UpdateSettings()
Try
Dim objModules As New Entities.Modules.ModuleController
objModules.UpdateTabModuleSetting(TabModuleId, "settingname" _
, txtSettingName.Text)
' refresh cache
Entities.Modules.ModuleController.SynchronizeModule(ModuleId)
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
That completes the code to Edit and Save the custom setting. Now you’ll want to retrieve that setting in your module.
4) In your user control (eg View_ModuleName.ascx, Edit_ModuleName.ascx), whether it’s the View, Edit, or another custom control, create a module level variable for the setting. In this case we’ve created a string, but you can “ctype” the variable into whatever type you need.
Private mSettingName As String = Common.Utilities.Null.NullString
5) Get the value of the setting and assign it to the module level variable mSettingName. This code should be placed in the Page Load event. Normally, it will assigned whether the page is in postback, or not.
If CType(Settings("settingname"), String) <> "" Then
mSettingName= CType(Settings("settingname"), String)
End If
The variable is now available to the entire user control (eg Edit_ModuleName.ascx.vb).
