SharePoint Sharpener

Obsessively Sharpening SharePoint

Custom Properties in a SharePoint web part

with one comment

It’s simple, really. Whenever you install a web part, it probably needs a few settings to work properly.

Maybe the web part needs to know the name of a specific list to be able to gather information and display it to the user. Or perhaps it requires the email address of the person who should receive status updates from the web part.

In any case you want the web part to be able to store simple textual and persistant information to be used in your code. You may of course decide to store this information in, say, a SQL Server table but – unless you need to store vast amounts of information – this is overkill and makes installation of the web part unecessarily difficult.


Custom web part properties to the rescue

You can add your own properties to the tool pane which appears when you access the settings of a web part in the browser. You can even make your properties appear in its own section, like this:



To achieve this, first add the following namespaces to your web part code:



Then, for each property you need, insert a code block similar to this:



Note that Category, WebDisplayName and WebDescription are optional but they do make your custom property much more readable for the end user.

In the above example, propEmail contains the default value of the property.


Written by Thomas Sondergaard

August 4, 2008 at 1:21 pm

One Response

Subscribe to comments with RSS.

  1. Good simple way which I was looking for.
    Thanks Thomas


    March 23, 2009 at 9:26 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: