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:
- Personalizable attribute needs to be specified
- 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; }
April 27th, 2010 - 16:24
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.
May 19th, 2010 - 14:51
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.