Monday, 14 April 2014

Custom User control to hide ribbon controls for unauthorized users

  • Sometimes we get requirement to hide few ribbon controls over the FARM.
  • one of the approach is to change something in global master page.

  • Global master page is located at: <<C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL>>
  •  Make sure to have copy of master page before editing.


  • Open V4.master page and add below control after last register tag prefix.
<%@ Register TagPrefix="HideRibbon" TagName="HideName" Src="~/_controltemplates/TrimRibbonItem/HideRibbon.ascx" %>

  • Now add below tag just before Body tag:  
<HideRibbon:HideName id="MyUserControl2" runat="server" /> 

  • Create an empty SharePoint project and add SharePoint mapped control with your custom logic as below

 
  • Error logging can be done in a div tag in the same control such that It will be run time and make the div hidden.
<div id="ErrorLog" runat="server" style="display:none;"></div> 
  • Hiding of ribbon controls can be done with the help of CSS in custom control 
<div runat="server" id="myDiv" style="display:none;"></div>
<style type='text/css'>
#Ribbon\.List\.CustomizeList-LargeMedium-1-1{display:none !important}
#Ribbon\.List\.CustomizeList-LargeMedium-0{display:none !important}
.ms-MenuUIULItem[text='Edit in SharePoint Designer']{display:none !important;}
.ms-MenuUIULItem[text='Site Permissions']{display:none !important;}
</style>


 






1 comment: