Search code examples
sharepointsharepoint-2010web-partsmoss

Set different value for Sharepoint custom property of same web part in multiple different pages


I have visual web part and i am attempting to set custom property unique value on each pages. For example i have two aspx pages. Deal.aspx and Fund.aspx. Both page is having same web part used. When i set the value custom property in web part of Deal.aspx the same value gets reflect in Fund.aspx page web part as well. I read about PersonalizationScope but it did not help for my scenario. Below is the custom property i have created.

    public static string ListName;
    [Category("Extended Settings"),
    Personalizable(PersonalizationScope.User),
    WebBrowsable(true),
    WebDisplayName("Enter List Name"),
    WebDescription("Please Enter a List Name")]

    public string _ListName
    {
        get { return ListName; }
        set
        {
            // Sample Validation
            Regex oRegEx = new Regex("[a-zA-Z]+");
            if (!oRegEx.IsMatch(value))
                throw new Microsoft.SharePoint.WebPartPages.
                    WebPartPageUserException(
                    "Please enter alphabeth characters only");
            ListName = value;
        }
    }

Solution

  • Problem is not in SharePoint or PersonalizationScope. It works fine. Problem is in static property ListName. Static properties are "shared" between all instances of the same class. So all your webparts will have the same value there.