Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
1  
Did u actually used the "Personalize this page" link when changing properties or the regular EDIT? –  C. Marius - MVP Apr 26 '12 at 12:22
1  
none of that, i created buttons that role is to redirect on the same page with querry string that change the color –  Hassan Apr 26 '12 at 12:50
    
i am also searching for same solution. Do you have any results? –  Evgeny Dec 10 '12 at 15:03
add comment

1 Answer 1

Web Part properties with PersonalizationScope=PersonalizationScope.User have the possiblity of storing that setting for individual users as well as for shared.

BUT the individual value is only set when editing the web part after selecting Personalize this page and the indivual value is only used when the page containing the web part is in Personal view.

Note that Wiki pages (and Wiki page libraries) do not support personal view, so you have to create a "Web Part Page" in some document library.

share|improve this answer
1  
and how could that be done by code problematically ? coz i just want the user the click on a color image –  Hassan Apr 27 '12 at 7:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.