Monday, November 10, 2008

Removing a menu item from the FormToolBar

As a follow up to the post about Removing a menu item from the Edit Control Block, the Approve/Reject button also appears on the FormToolBar for "View Item" in a document library with the content approval for submitted items set.

To remove this button from the FormToolBar the following piece of code was used in the code in the ControlTemplate associated with the Custom Document Library's content type.

Control apprejButton = Utils.FindControlRecursive(this.Page, "diidIOAppDenyItem");
if (apprejButton != null)
apprejButton.Visible = false;

This uses a FindControl method that searches through all the containers on the page for the Approve/Reject button (Credit goes to Jeff Atwood's blog):

private Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
{
return root;
}

foreach (Control c in root.Controls)
{
Control t = FindControlRecursive(c, id);
if (t != null)
{
return t;
}
}

return null;
}

No comments: