Ram Prasad
 

'Open Tool Pane' link in a custom webpart

Jan, 29 2012
 
1 min/s
 
 

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 properties 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 your webpart whose HREF should be set to the below JavaScript function

MSOTlPn_ShowToolPane2Wrapper()

The prepared anchor tag should look as shown below

<a href="javascript:MSOTlPn_ShowToolPane2Wrapper('Edit',this,'ID of the webpart');" title="Open The Tool Pane">Open The Tool Pane</a>