I'am trying to create a webpart with a personalizable property scoped to the user level.
[ToolboxItemAttribute(false)]
public class TestWebpart : WebPart
{
static int _backColor = 1;
[WebBrowsable(true)]
[Personalizable(PersonalizationScope.User)]
public int backColor
{
get { return _backColor; }
set { _backColor = value; }
}
// Visual Studio might automatically update this path when you change the Visual Web Part project item.
private const string _ascxPath = @"~/_CONTROLTEMPLATES/SharepointTextEditor/TestWebpart/TestWebpartUserControl.ascx";
protected override void CreateChildControls()
{
TestWebpartUserControl control = Page.LoadControl(_ascxPath) as TestWebpartUserControl;
control.colorIndex = this.backColor;
Controls.Add(control);
}
}
In the web part user control codebehind I style some controls based on the currently selected color:
public int colorIndex { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
switch (color)
{
case x: div1.InnerHtml = blueStyle;
colorIndex = x;
new TestWebpart().backColor = 3;
break;
case y: div1.InnerHtml = goldStyle;
colorIndex = y;
new TestWebpart().backColor = 3;
break;
}
}
The problem is that the property changes aren't persisted on an user base. It do save the status but the same for all the users. If I make a change made for one user, all the other users see the change as well.
Do I miss something to make it work correctly?