how to set Personalizable attribute to generic list in webpart?

511 views Asked by At

I develop web part with custom editor part and faced with this question.
Is it possible in web part set Personalizable attribute to generic List? For example I want something like this:

[WebBrowsable(false)]
[Personalizable(PersonalizationScope.Shared)]
 public List<AnnouncementItem> Announcements
 {
      get { return _announcements; }
      set { _announcements = value; }
 }

Is it possible, and what kind of types at all can be used as "Personalizable"?
Thanks.

Solution:
I use a custom EditorPart to select multiple lists using AssetUrlSelector, but I need a way to personalize this collection for end user.List<of custom objects> doesn't work, but I found that List<string> (and only string) work perfectly. So, I get required lists in EditorPart and pass their to the web part using List<string>.

2

There are 2 answers

0
knight0323 On

Try using a custom EditorPart to add/remove items from the collection. I've never built a web part that personalized a collection so I don't know if it works but I'd definitely try the collection with an EditorPart. If it doesn't work, serialize XML into a string property.

0
Rich Bennema On

Your question does not seem to match your code. Your code shows a collection of custom objects. I doubt an end user will be able to set such a property. To have a property that points to a generic list, you would probably be better off defining the property as a string that contains the URL to a list.