Wednesday, January 18, 2006

Default values of webpart properties

When you add a webpart to a page, the "Allow Close" checkbox is automatically checked. This enables the users to close a webpart. Most users don't know how to retrieve this closed webpart and call the helpdesk, causing extra calls.

About a month ago a customer asked me if it is possible to uncheck the "Allow Close" checkbox by default. I went on a big Internet search and found the following solutions:

  1. Add locklayout="true" to zone declaration
  2. Change the webparts dwp file by adding tags

Add locklayout="true" to zone declaration
<WebPartPages:WebPartZone runat="server" Title="loc:TitleBar" ID="TitleBar" LockLayout="true" AllowPersonalization="false">

Specifies 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. 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). This behaviour is not desireable. I only want the Allow Close to be changed.

Change the webparts dwp file by adding tags
It is possible to add some tags to the webparts dwp file, which define a default value for a certain property. These tags are:

<?xml version="1.0" encoding="utf-8"?>
<WebPart xmlns:xsd="" xmlns:xsi="" xmlns="">
    <Title>Content Editor Web Part</Title>
    <Description>Use for formatted text and images.</Description>
    <Height />
    <Width />
    <DetailLink />
    <HelpLink />
    <PartImageSmall />
    <MissingAssembly />
    <IsIncludedFilter />

When the tag "<AllowRemove>false</AllowRemove>" is added to the dwp file, the "Allow Close" checkbox is unchecked (for that webpart) by default!

No comments: