WebPart Custom Settings

A WebPart is a component we can add to a SharePoint Site to perform a specific task and can be used multiple times. Each WebPart has settings that can be divided into three categories – Appearance, Layout and Advanced. Sometimes, these settings are enough, but we usually need to add our own categories of settings, that are specific to the WebPart we are developing.

Adding extra setting is fairly simple. We first need to add a property (a flexible mechanism, a method for reading and writing values) of the same type as the type of setting and add attributes, that define if it will be visible among settings, which group it will be shown in, it’s title, description, default value and if it will be editable.

All that we have to do after that is to attach the methods to controls that make the settings visible.

This way, we created additional settings. The problem is, we are limited to a text field (for text, numbers and dates), a confirmation field and a drop down menu. This limits the functionality and simplicity of custom settings.

If we want to improve the functionality and simplicity of settings, for example adding a date picker instead of requiring users to manually enter a date and time, we must first overwrite the class toolpart, into which we add our own type of settings and specify the order in which the settings will be shown (what will be shown first – default or custom settings).

After that, we write our own class, which inherits it’s properties from the default one. In this class, we add a window, which will, as we specified earlier, be shown before or after the default settings. To this window, we attach our settings and their properties. The settings are also of the property method, but they are not limited to a text field, a drop down or a choice field. We can add our own type that we custom make (for example coordinates). After that, we need to overwrite the default functions for canceling or enforcing settings (apply changes, ok and cancel). Here we must specify what should happen, when a user clicks on one of these buttons. which is to save settings and apply them to the WebPart. When we have written these functions, the WebPart settings will be effective. This way, we created custom WebPart settings.

Leave a Reply

Your e-mail address will not be published. Required fields are marked *