Sunday, July 19, 2009

Locking webparts in webpart zone

Scenario:
We wanted to lock some of company wide Web parts in some of web part zones so they cannot be deleted or modified by another one for consistency purpose.

Solution:
WebPartZone supports a property LockLayout.Setting it to true did the trick.

This property basically controls whether or not Web Parts within the zone can be added, deleted, resized, or moved. The LockLayout property works the same regardless of whether the Web Part Page is in personal or shared view.

Sample Declaration:

 <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Left" Title="loc:Left" AllowCustomization="false"   AllowLayoutChange="false" AllowPersonalization="false" LayoutOrientation="Vertical" LockLayout="true"  />
 locked

How does it work:
If set to True, the specific Web Part properties for each Web Part in the zone that are affected are: Zone (ZoneID), Part Order (PartOrder), Visible on Page (IsVisible), Height (Height), Width (Width), Allow Close (AllowRemove), and IsIncluded (the Close command on the Web Part menu). Other Web Part properties are not affected.

If set to False, the Web Part properties determine whether modifications can be made (along with the appropriate site permissions).

0 comments: