Saturday, March 14, 2009

Adding custom properties to webparts

Another handy tip for beginners; ever seen those properties that show up in the toolpane when u want to edit webpart? there is much more that can be added to suit your customization needs.
the general format of c# properties consists of a get and set method for the required value

if u add the following piece of code to the existing you shd get what u want;

[Personalizable(PersonalizationScope.Shared)] //enable personal views

[WebBrowsable(true)]

[System.ComponentModel.Category("My Properties")] /*create category for new property, will default to miscellaneous if undefined */

[WebDisplayName("Another Property")]



private string _anotherProperty;

public string AnotherProperty

{

get { return _anotherProperty; }

set { _anotherProperty = value; }

}

watch out for differences between sharepoint and asp.net webparts

Good luck!

No comments:

Post a Comment