I.M.Possible What is impossible with men is possible with God

19Jan/102

SharePoint Web Part Custom Properties

In my current project, I am creating a SharePoint web part that simply renders a custom .NET User Control from a certain location. I want the user to be able to configure the User Control's properties through the Web Part properties. Therefore I followed the MSDN instruction on how to create a web part with custom properties. However, somehow the custom properties just doesn't show up.

So, after scratching my head for a couple of hours (not literally), I found something that, I think, was not accurately specified:

  1. Personalizable attribute needs to be specified
  2. Use WebBrowsable instead of Browsable attribute

This is the code-snippet that works for me:

[Category("Custom Properties")]
[DefaultValue(true)]
[Personalizable(PersonalizationScope.Shared)]
[WebPartStorage(Storage.Shared)]
[FriendlyNameAttribute("Include lists")]
[WebBrowsable(true)]
[XmlElement(ElementName = "IncludeLists")]
public bool IncludeLists { get; set; }
Comments (2) Trackbacks (0)
  1. Do you know, which attributes are mandatory ? After trying out I think that at least the attributes WebBrowsable(true) and Personalizable(…) are required for a property to be shown up as editable. But I can’t find a real specification in the web.

    • I couldn’t find the ‘official’ documentation anywhere on MSDN that specifies which attributes are mandatory. However, as you have mentioned, those two attributes are sufficient to make custom properties on web part to work. Other properties are sometimes recommended to have, to make the custom property more user-friendly and descriptive.


Leave a comment


Login with Facebook:

No trackbacks yet.