Am using DNN 7 with C#. I've seen some basic examples on how to create a module - very helpful, got that sorted, all good. Can also update settings without any issues.
However, am I'm struggling with editing a module. in DNN 7 you can click the settings option (cog icon) or edit option (pencil icon). If you use the pencil icon it brings up your custom module edit page. I can't seem to get this to work. What I wanted to do was update a few values (lets say text boxes) and write them back to a table built for my custom module - those values are then used by the View.ascx when the module is displayed. On the edit page, the Update button fires, but values it gets are the original ones displayed on screen - not newly entered values.
What am I doing wrong ?? If you can't figure out what I've missed then some sample code for editing a module would be great !
Edit.ascx
<
div
class
=
"dnnForm dnnClear"
>
<
div
class
=
"dnnFormItem"
>
Below you can edit the content that appears within this module.
</
div
>
<
fieldset
>
<
div
class
=
"dnnFormItem"
>
<
dnn:label
ID
=
"lblTest"
runat
=
"server"
/>
<
asp:TextBox
ID
=
"txtTest"
runat
=
"server"
/>
</
div
>
</
fieldset
>
<
div
class
=
"bexLocUpdDiv"
>
<
ul
class
=
"dnnActions dnnClear"
>
<
li
>
<
asp:Button
runat
=
"server"
ID
=
"cmdUpdate"
OnClick
=
"cmdUpdate_Click"
Text
=
"Update"
Width
=
"100px"
CssClass
=
"dnnPrimaryAction"
/>
</
li
>
<
li
>
<
asp:Button
runat
=
"server"
ID
=
"cmdCancel"
OnClick
=
"cmdCancel_Click"
Text
=
"Cancel"
Width
=
"100px"
CssClass
=
"dnnSecondaryAction"
/>
</
li
>
</
ul
>
</
div
>
</
div
>
Edit.ascx.cs code:
/// <summary>
/// CmdUpdateClick runs when the update button is clicked
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks></remarks>
protected
void
cmdUpdate_Click(
object
sender, EventArgs e)
{
try
{
var testValue = txtTest.Text;
// my controller with some code to write back to DB
// PROBLEM: Always writes the original value, not the latest value entered by user
SampleController.Set(testValue);
// PLEASE dont worry too much about what's in controller.. I used setting code below to confirm testValue is the issue, not controller code.
/*
// TEST ONLY - using settings 'cos I know they work ..
// just checking the value of my textbox .. it confirmed the original value was being accessed
ModuleController modules = new ModuleController();
modules.UpdateModuleSetting(ModuleId, "TestValue", testValue );
*/
// redirect back to page
Response.Redirect(Globals.NavigateURL(),
true
);
}
catch
(Exception exc)
{
Exceptions.ProcessModuleLoadException(
this
, exc);
}
}