"Open Tool Pane" link in a custom webpart
Most of the times when we create custom webparts, we define custom properties in it.
These properties are used to store some configuration details for the web part to
function. In many custom web parts I saw, developers use custom properties in a
webpart to store the data source for the web part. Data sources can be a List name,
Document Library name or a Connection string for SQL Server database etc.,
While creating pages and adding web parts, if authors leave the propeties empty,
the web part may throw some error.
If you add a Content Query Web Part in your page, and leave the properties empty,
then it displays a link to the user, which says Open Tool Pane. On
clicking this link the tool pane of the webpart is opened. Its a good practice to
provide this type of link on our custom web part as well, when the properties are
left empty. Lets see how this can be achieved
Before processing with the logic/data in the custom webpart, check if the required
properties are empty. If they are found to be empty, then render an anchor tag in
The prepared anchor tag should look as shown below
I created a sample webpart to show this working, you can download it from
here. In this sample
the Open Tool Pane link is displayed only when the page is in design mode.