BlogEngine.NET Settings Not Saving With Values Other Than Text
You may be using BlogEngine.NET 2.7 for your blogging solution like I am and have run into a rather sticky situation in which Settings values from non scalar entities are not saving the values of properties if they are anything other than text properties. This was a little frustrating to me since I have used BlogEngine.NET in the past but the framework and thus the code has grow what seems to be exceeding complex.
So where do you look in order to correct this? Well, in the admin section of the source code there is a user control for Settings.ascx.If you look specifically at the code you will notice that the Textbox items are the only ones that check to see if the particular setting that you are updating is a scalar value or not. All of the other ones merely try to update the values. Not exactly what you want to happen. So if I want to say, have Checkboxes properly add their values then I have to update the code that starts around line 129 of the Settings.ascx.cs file like this.
1: foreach (Control ctl in this.phAddForm.Controls)
3: switch (ctl.GetType().Name)
5: case "TextBox":
7: var txt = (TextBox)ctl;
9: if (this.Settings.IsScalar)
11: this.Settings.UpdateScalarValue(txt.ID, txt.Text);
15: this.Settings.AddValue(txt.ID, txt.Text);
20: case "CheckBox":
22: var cbx = (CheckBox)ctl;
23: if (this.Settings.IsScalar)
25: this.Settings.UpdateScalarValue(cbx.ID, cbx.Checked.ToString());
29: this.Settings.AddValue(cbx.ID, cbx.Checked.ToString());
34: case "DropDownList":
36: var dd = (DropDownList)ctl;
37: this.Settings.UpdateSelectedValue(dd.ID, dd.SelectedValue);
41: case "ListBox":
43: var lb = (ListBox)ctl;
44: this.Settings.UpdateSelectedValue(lb.ID, lb.SelectedValue);
48: case "RadioButtonList":
50: var rbl = (RadioButtonList)ctl;
51: this.Settings.UpdateSelectedValue(rbl.ID, rbl.SelectedValue);
So now with this small change my settings page will update the values appropriately.
Hopefully, this will help someone out that is trying to implement or create their own extensions for the platform.