I have noticed a bug that occurs on all custom web parts I created.
Let's assume I have following web part (sandbox solution) with two properties:
using System;
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;
namespace SampleSandboxSolution.VisualWebPart1
{
[ToolboxItem(false)]
public partial class VisualWebPart1 : WebPart
{
[Category("Miscellaneous")]
[Personalizable(PersonalizationScope.Shared)]
[WebBrowsable(true)]
[WebDisplayName("Option1")]
[WebDescription("Option1")]
public bool Option1 { get; set; }
[Category("Miscellaneous")]
[Personalizable(PersonalizationScope.Shared)]
[WebBrowsable(true)]
[WebDisplayName("Option2")]
[WebDescription("Option2")]
public bool Option2 { get; set; }
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeControl();
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
I've put this web part on my page and I'd like to modify its properties (via "Edit Web Part" from context menu). Option1 and Option2 are unchecked by default. So, I select Option1 and press "OK". Unfortunately, when I enter the properties again without refreshing the page, the checkboxes are unchecked again.
Similar, more annoying scenario:
- Check "Option1", leave Option2 unchecked
- Press OK and refresh the page
- Open web part's properties - Option1 will be checked now, Option2 will be unchecked - as expected
- Check Option2 (Option1 and Option2 should be checked now)
- Press OK, but do not refresh the page
- Open web part's properties - all checkboxes are unchecked again, even Option1!
When I edit web part's properties, it seems that on clicking "OK" button the changes are being saved - but without refreshing the page it does not read those settings until next page load, all the properties are cleared.
Is this SharePoint's bug? Or should I do something to prevent that situation?
Thank you in advance