Customizing SharePoint Edit and Display form toolbars

There are a number of Blog posts out there on the topic of toolbar customizations.  If you take the Custom Actions feature approach, you can add new toolbar choices at different levels (Web Application, Site Collection, etc.). You can also customize a copy of DefaultTemplates.ascx and load that user control set with a hidden web part in lieu of the default toolbar.

What if you need to remove a toolbar choice on exactly 1 DispForm.aspx page?

I recently had this requirement on a SharePoint assignment where I had used a CustomCore.js to security trim the Item context menu by manipulating the ECB (EditControlBlock). I had to follow that up with a simple way to eliminate the “Edit Item” choice that remained on the toolbar of the DispForm.aspx page when Visitor level users selected the View Item choice from the context menu.

This is a first-try hack, but the JavaScript to hide elements of the toolbar is pretty straight-forward.

<script language=”javascript” type=”text/javascript”>
  //This line is necessary so the javascript method gets loaded on the page.
  function hideFields()
     var control = document.getElementById(“ctl00_m_g_817757e4_87fc_45a3_ad3c_f88ce0e48c70_ctl00_ctl01_ctl00_toolBarTbl_RptControls_diidIOEditItem_LinkText“);”none”; // <td> containing the vertical separator”none”; // <tr> containing the icon and text

From here you should obtain the control base/web part ID and concat that to the “_toolBarTbl_RptControls_diidIOEditItem_LinkText” part of the control ID string. Or you can write a more sophisticated JavaScript routine that finds the control simply using the “diidIOEditItem_LinkText” suffix and recursively moves up the tag tree looking for the <tr>’s containing the Edit Item icon and link text anchor tags and finally the <td> containing the separator ‘|’.


About generation12

I am a SharePoint/.NET consultant in the twin cities.
This entry was posted in Customization and tagged . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s