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)

   2: {

   3:     switch (ctl.GetType().Name)

   4:     {

   5:         case "TextBox":

   6:             {

   7:                 var txt = (TextBox)ctl;

   8:  

   9:                 if (this.Settings.IsScalar)

  10:                 {

  11:                     this.Settings.UpdateScalarValue(txt.ID, txt.Text);

  12:                 }

  13:                 else

  14:                 {

  15:                     this.Settings.AddValue(txt.ID, txt.Text);

  16:                 }

  17:             }

  18:  

  19:             break;

  20:         case "CheckBox":

  21:             {

  22:                 var cbx = (CheckBox)ctl;

  23:                 if (this.Settings.IsScalar)

  24:                 {

  25:                     this.Settings.UpdateScalarValue(cbx.ID, cbx.Checked.ToString());

  26:                 }

  27:                 else

  28:                 {

  29:                     this.Settings.AddValue(cbx.ID, cbx.Checked.ToString());

  30:                 }

  31:             }

  32:  

  33:             break;

  34:         case "DropDownList":

  35:             {

  36:                 var dd = (DropDownList)ctl;

  37:                 this.Settings.UpdateSelectedValue(dd.ID, dd.SelectedValue);

  38:             }

  39:  

  40:             break;

  41:         case "ListBox":

  42:             {

  43:                 var lb = (ListBox)ctl;

  44:                 this.Settings.UpdateSelectedValue(lb.ID, lb.SelectedValue);

  45:             }

  46:  

  47:             break;

  48:         case "RadioButtonList":

  49:             {

  50:                 var rbl = (RadioButtonList)ctl;

  51:                 this.Settings.UpdateSelectedValue(rbl.ID, rbl.SelectedValue);

  52:             }

  53:  

  54:             break;

  55:     }

  56: }

 

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.

 

Cheers!
AJ