Custom Properties in a SharePoint web part
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.