Wednesday, March 28, 2012

Atlas WebPartZones Visible property not working correctly

Hi All,

I have an ASPX page that contains three WebPart Zones. As per therequirements, one of the Zones, say rightZone, needs to be hidden for,say X, role. For this I check the user role in the Page_Load event, andif logged-in user's role is X then I set rightZone's Visible propertyto false. This works fine using ASP.NET 2.0 WebParts.

I wanted to have drag-and-drop in FireFox as well; therefore, I used"Atlas" (March CTP) WebPartManager and WebPartZone to achieve the same.This works fine for all roles except X. That is, when an X type userlogs in, a JavaScript error is displayed. It goes something like this:

Could not find 'rightZone' element.

On further investigation I found out that if set the rightZone isrendered even though its visible property is set to false. I guessthat's the reason for JavaScript error.

Please let me know if this is a bug in "Atlas" or I am doing something wrong.

Thanks.

~Vihar

It's generally not a good idea to set Visible=false on a WebPartZone. The Visible property only controls whether the WebPartZone is rendered, not whether the WebPartZone participates in the WebParts control set. For example, if a WebPartZone has Visible=false, it will still appear in the list of WebPartZones in the CatalogZone and LayoutEditorPart. This will be confusing to users, since they will be able to add or move a WebPart to an invisible WebPartZone.

A better idea is to remove the WebPartZone from the page completely. You would need to do this in the PreInit phase of the lifecycle.

All this aside, you have indeed found a bug in Atlas, and it applies to any server control, not just WebParts. The xml-script for a control is always being rendered, even if the control is not visible. This is a bug because the xml-script for a control usually assumes that the control was actually rendered. We'll work on fixing this for a future release. Thanks.

-Mike
For now you could use a workaround to add the css style with display:none.

No comments:

Post a Comment