1

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?

3
  • 1
    Did u actually used the "Personalize this page" link when changing properties or the regular EDIT? Apr 26, 2012 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, 2012 at 12:50
  • i am also searching for same solution. Do you have any results?
    – Ievgen
    Dec 10, 2012 at 15:03

1 Answer 1

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.

1
  • 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, 2012 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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