Thursday, August 17, 2006

 

Disable the edit verb on a web part: practically impossible

This thread on ASP.NET forums called my attention to a fact about ASP.NET 2 web parts that I had never noticed before. When you set AllowClose on a web part to False, the web part infrastructure will hide the Close verb from the user. The setting will not only prevent the action of Closing with an exception, but will also hide forbidden options in the UI.

However, when you set AllowEdit to False, the Edit verb does not disappear; when you select Edit, the EditorZone will not display any tool part, but you can still switch to edit mode. Why would that be?

I checked the code with Reflector and indeed, in the WebPartChrome.ShouldRenderVerb method, the logic seems to make and exception for the Edit verb: the right display mode is checked, but no check for the AllowEdit property on the web part. Also, the designers of the framework seem to have intentionally made fixing this very hard: you can create a custom subclass of WebPartChrome, but

It escapes me why it would be so bad to have the opportunity to remove verbs that were added by the base implementation and I am still wondering why we should not hide the Edit verb from users when editing is not allowed anyway.

It all looks a bit sloppy to me.

Labels:


This page is powered by Blogger. Isn't yours?