SharePoint Web Part Visibility Filter Web Part

I was recently contacted through my blog with a question on how to dynamically hide/show a web part on a web part page based on a user’s selection of a UI element on the page.  While there’s several methods you could employ to perform this task, one nice, neat implementation that you could leverage is posted up on our CodePlex site called the SharePoint Web Part Visibility Filter Web Part.

Through the implementation of this web part, you have the ability to accomplish the following scenario:

You have a standard SharePoint list containing a listing of items that offer selection options and a ‘Item Detail’ part, which happens to be an implementation of the Visibility Filter Part, that will show detail information based on the user selection from the list above it.

SharePoint Visibility Filter Web Part

In the screenshot below, upon making a different selection from the list of items, a new details web part is now displayed showing details for the selected item.

SharePoint Visibility Filter Web Part

Now this implementation is built upon concepts that have been around SharePoint for quite some time, like connected web parts, however, this is a decent implementation that addresses the requirement for being able to dynamically hide and show web parts based on some dynamic criteria.

Head over to CodePlex and take a look at this project.  Pretty interesting!

A few caveats to keep in mind (taken from the notes on the project’s CodePlex page):

  • The web part needs to render itself before the web part(s) that may be affected by it (hidden or unhidden), so you need to place it in a web part zone above the potentially affected web parts.  Web parts are rendered in order of their zone indexes, and then their index within each zone.  If a web part is rendered before the Visibility Filter Web Part that affects it, its visibility will not appear to have changed because it was already rendered.  In other words, your Visibility Filter web parts should probably be placed at the top of your page, before all other web parts.
  • This web part does not actually generate any visible HTML output to the page (it affects other web parts) but can emit Javascript to the page. By default, when it is placed on a page, its visibility is automatically set to Hidden. The Javascript it generates is to modify the titles of web parts that it is unhiding (if any). SharePoint adds the string “(Hidden)” to any web parts that are initially hidden and that remains even if this web part unhides them, so it generates Javascript to find the titles of those unhidden web parts and removes the “(Hidden)” string from their title.
  • You may need to include multiple instances of this web part on a page to selectively hide/unhide web parts.
  • Although this web part can dynamically hide other web parts, those web parts will still internally “render”. They are hidden using the SharePoint web part API (not via CSS or Javascript on the page) so the data from the web part will not be generated on the page at all, but SharePoint will still “execute” the web part code, so hiding it will not reduce any significant load on the server. In other words, if you have a web part such as a Data View Web Part that queries a SQL database, it will still query the database even if this web part hides it, although the result of the rendering will not be output to the browser. That is to say, if you have 10 web parts on a page and this web part hides 5 of them, except for the time it takes to load the page in the browser, the page will not render much faster because those 5 web parts are hidden. From the server side, it would be as if all 10 web parts were still on the page.

Enjoy!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by WP-CopyRightPro