SharePoint WebPart Property Attributes
I wanted to put this information out there because it was not well published when I was building WebParts for the first time. When you build a WebPart in MOSS 2007 you have the ability to expose the public properties of the WebPart in the editor pane of the WebPart page. This allows you to set some administrative values for the WebPart behind the scenes. In order to make this happen you have to tag the property as being Web Browsable.
Unfortunately most of the documentation only gives information on the WebBrowsable and Personalizable attributes. However there are a few others that you might find valuable to know about. Some of the other attributes are listed below along with explanations and links to further resources.
WebBrowsable [WebBrowsable(True)]
"Indicates whether the designated property of a Web Parts control is displayed in a PropertyGridEditorPart object." (MSDN)
WebPartStorage [WebPartStorage(Storage.Personal)]
This attribute specifies what type of storage options the WebPart will make use of. The most common is Storage.Personal. "This property can be personalized by individual users. Its WebPartStorageAttribute value is Storage.Personal, which specifies that the property can be stored on a per-user basis. Only users with the Personalize Web Part pages right can set this property." (MSDN)
Personalizable [Personalizable(true)]
Allows users the ability to personalize settings for the WebPart.
WebDispayName [WebDisplayName(string)]
Defines the Friendly Name for a property of a WebPart control. This is the name that will show up in the editor screen.
WebDescription [WebDescription(string)]
Defines the string value to use as a ToolTip for a property of a Web Parts control. (MSDN)
SPWebCategoryName [SPWebCategoryName(string)]
Defines the friendly or localized name of the category of a property in the CustomPropertyToolPartcontrol inside the ToolPane.
ConnectionProvider [ConnectionProvider(string)]
Identifies the callback method in a server control acting as the provider in a Web Parts connection, and enables developers to specify details about the provider's connection point. (MSDN) This is used to create connectable WebParts.
ConnectionConsumer [ConnectionConsumer(string)]
Identifies the callback method in a server control acting as the consumer in a Web Parts connection, and enables developers to specify details about the consumer's connection point. (MSDN) This is used to create connectable WebParts.
Below is an example of how to use these attributes in your WebPart code.
[WebBrowsable(true),
Personalizable(false),
WebPartStorage(Storage.Personal),
WebDisplayName("User Name(Domain\\username)"),
WebDescription("User to display in the WebPart."),
SPWebCategoryName("Options")]
public string UserLoginName
{
get { return _loginName; }
set { _loginName = value; }
}
Happy coding!
No comments:
Post a Comment