Zal,
My apologies; thisturns out to be a lot harder than I initially thought.
Setting the AllowEdit property of your part to False will prevent your part from being edited. You can just set the AllowEdit="False" property on your user control (VS.NET will put squigglies under it, but never mind). When you try to edit this part, the Edit zone will show, but will have no ToolParts loaded.
This is not what you want: you want the verb to disappear. This turns out to be hard. Adding custom verbs to a part is easy, but removing them is not. The snippet below gives you an example of how to create acustom zone with acustom WebPartChrome that will make your verbs disabled where Editing is not allowed. Setting Visible to false will turn of the verb for other web parts in the same zone as well (or rather: all parts after the one with AllowEdit=false).
public class HideEditZone : WebPartZone
{
public HideEditZone()
{
}
protected override WebPartChrome CreateWebPartChrome()
{
return new MyChrome(this, this.WebPartManager);
}
}
public class MyChrome : WebPartChrome
{
public MyChrome(WebPartZoneBase zone, WebPartManager mgr)
:
base(zone, mgr)
{ }
protected override WebPartVerbCollection FilterWebPartVerbs(WebPartVerbCollection verbs, WebPart webPart)
{
WebPartVerbCollection defaultResult = base.FilterWebPartVerbs(verbs, webPart);
foreach (WebPartVerb verb in defaultResult)
{
if (verb == this.Zone.EditVerb)
{
verb.Enabled = webPart.AllowEdit;
}
}
return defaultResult;
}
}