Take the 2-minute tour ×

Here is the problem: using SPD is easy to change properties to not allow users to close / minimize webparts from a wp zone:

webpartzone edit properties

Now how can we do that in code ? I have more then 30 aspx webpart pages on a site, I want to be able to do that so no one can change webparts properties (close, delete them etc.)

The only thing I did find is this link: spwebpartzonetools.

Reading more in SDK at: wss 3.0 sdk, at the second Important paragraph it says:

Although you can add Web Parts to the Display, Edit, and New forms for list items (DispForm.aspx, EditForm.aspx, and NewForm.aspx), doing so is not recommended or supported in Windows SharePoint Services. Adding Web Parts to list view pages (AllItems.aspx) is supported.

So that's my mistake that I want to fix :). I did break that rule. My problem can be fixed in SPD but I don't know if that can be fixed in code.

The mistake was "inspired" from one of the fabulous 40 Templates : BudgetingTrackingMultipleProjects.wsp. There on Projects list, on DispForm.aspx, Microsoft add more webparts to create a master-detail form.

share|improve this question
add comment

4 Answers

up vote 1 down vote accepted

I've solved my problem like this: if you open the DispForm.aspx in SPD and modify web part zone properties then in the souce code (aspx) we can see this line:

 <WebPartPages:WebPartZone runat="server" FrameType="None" ID="Main" Title="loc:Main" allowlayoutchange="false" allowpersonalization="false" allowcustomization="false">

So then I've create a simple console app, that visits each list, get the url of its DispForm.aspx and open it like a regular text file. So I'm not using any API or smth, just SPWeb.GetFile(String) - to get the SPFile and SPWeb.GetFileAsString(url) to get the aspx content as string. Then I'm injecting the attributes (allowlayoutchange / allowpersonalization / allowcustomization) in the line presented above using just string search and replace methods.

Then save the content back to aspx file using SPFile.SaveBinary(). Thats it, next time DispForm.aspx is requested the contrib. user can't do a thing with webparts from there. So that is my method to change web part zone properties. I'm so looking forward to see other solutions.

share|improve this answer
add comment

You should be able to set these properties after provisioning the web parts (that is if you havent done as Chris say and defined it in the manifest of the web part) by iterating the web parts in the SPLimitedWebPartManager (beware of leak) on each page and set the AllowClose, AllowHide, AllowMinimize etc properties.

hth Anders Rask

share|improve this answer
Thanx Anders, please look above to the comment for Chris. I should have specify from begining that the AllowHide=false is not working in my case. (webparts on DispForm.aspx - after click on View Item from ECB) –  Ovidiu Becheş-Puia Jan 21 '10 at 19:25
add comment

You could also set this to the WebPartZone control (in code or in aspx). Use the LockLayout property, for instance like this:

<WebPartPages:WebPartZone LockLayout="true" runat="server"...>...</...>


share|improve this answer
add comment

Do you need to do it in code? If your requirement is simply to stop users making these changes in your web parts, this is typically dealt with by provisioning the web part with properties which specify this behaviour e.g.:

       <type name="xxxxx.SharePoint.Common.WebParts.SiteDirectoryWebPartWrapper,
 xxxxxx.SharePoint.Common, Version=, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxx" />
         <property name="AllowZoneChange" type="bool">False</property>
         <property name="AllowHide" type="bool">False</property>
         <property name="AllowMinimize" type="bool">False</property>
         <property name="AllowEdit" type="bool">True</property>
         <property name="AllowConnect" type="bool">False</property>
         <property name="ExportMode" type="exportmode">All</property>
         <property name="Hidden" type="bool">False</property>
         <property name="TitleUrl" type="string" />
         <property name="Description" type="string">Displays a list of sites
 for the current area (e.g. 'teams') in a treeview. </property>
         <property name="Title" type="string">xxxxx Site Directory
 Web Part</property>
share|improve this answer
Thanx Chris, to setup those properties to webparts was the first thing I did try. But in my case, I have the view form (DispForm.aspx) with webparts in it. Why I have that ? Well when contrib. user clicks on "View Item" from ECB menu, I add more webparts connected with the current item being displayed. So far so good, BUT the contributor user then has the possibility to close or delete the webparts on this page (DispForm.aspx). Is doesn't make any sense to me. Since DispForm.aspx is a web part page, why a user with edit permision on the recored displayed can also close other webparts ? –  Ovidiu Becheş-Puia Jan 21 '10 at 19:23
add comment

Your Answer


