This post is migrated from previous hosting provider. There are still some issues with old posts. Please make a comment on this post with any issues.

Why you should not allow users to Close Web Parts

Tags: SharePoint, Web Parts

A Web Part, in SharePoint or not, has a Verb that allows the Web Part to be Closed. Closed means that the Web Part is just closed (not rendered) and not deleted, which is a separate Web Part Verb. Closing Web Parts can cause headache for your users and even a really bad performance.

Note: To delete a Web Part you have to go in to Edit mode for the page. Close can be done directly from the Web Part menu.

Headache for your users

Advanced Web Part gallery and options When you close a web part it is visually removed from the page and can only be retrieved back by appending ?Contents=1 to your web part page URL or by editing the page, click Add a Web Part, click Advanced Web Part gallery and options and then select Closed Web Parts. None of these options are intuitive and my guess is that not many administrators or users are aware of this.

Most probably your users will end up creating and configuring a new Web Part, which eventually will be closed also, and so on.

This will make your Web Part storage grow and after a while your page will start to perform bad. It can get even worse when you allow the users to customize their own pages.

Bad performance

Why does the page perform so badly when you have a lot of closed Web Parts? The answer is twofold; first of all it takes storage and resources to handle these closed web parts and secondly the closed Web Parts are actually created on every page load! They are not rendered but the Web Part Manager control creates all Web Parts (closed or not) during the pre render phase and checks if any of the Web Parts has any client scripts that needs to be registered with the Web Part Page Services (WPSC) framework.

Note: if you are creating your own Web Parts, based on the SharePoint WebPart class, and you do not need to register any client scripts then override the RequiresWebClientScript and return false.

Nothing else is done with the closed Web Parts, but if you (god forbid) have any initializations in the constructor you can make the situation even worse.

Resolution

Fortunately this problem can be solved in a very easy way; you can prohibit a Web Part from being closed by using the built-in Web Part property AllowClose and set it to false (default is true). You can do this in three different ways;

  1. Allow Close You can change the value of the Allow Close property by editing the Web Part and under Advanced you will find an Allow Close check box
  2. If you develop the Web Part yourself then you can override the property in your class
  3. You can modify the .webpart or .dwp file and set the value of the AllowClose property

10 Comments

Comments have been disabled for this content.

About Wictor...

Wictor Wilén is the Nordic Digital Workplace Lead working at Avanade. Wictor has achieved the Microsoft Certified Architect (MCA) - SharePoint 2010, Microsoft Certified Solutions Master (MCSM) - SharePoint  and Microsoft Certified Master (MCM) - SharePoint 2010 certifications. He has also been awarded Microsoft Most Valuable Professional (MVP) for seven consecutive years.

And a word from our sponsors...