Scenario: Show menu item in SharePoint ECB based on a condition e.g when versioning is enabled in the List or Document Library.

Solution: One of the ways of adding items to ECB is to create a delegate control. In the control the code is written in two JavaScript functions Custom_AddListMenuItems and Custom_AddDocLibMenuItems. The SharePoint context object (ctx) provides lots of information like the list template, list name etc. Its verEnabled property specifies whether the versioning is enabled in the list or not. please visit Tom Van Gaever - Blog for a complete list of properties provided by ctx object, 

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
       <Control Id="AdditionalPageHead"
           ControlSrc="~/_CONTROLTEMPLATES/NY.ExportVersionHistory/ECBDelegateControl.ascx" />

In the ascx control we need to define Custom_AddListMenuItems(m, ctx) and Custom_AddDocLibMenuItems(m, ctx)

<script type="text/javascript">
    function Custom_AddListMenuItems(m, ctx) {
        AddECBMenuItems(m, ctx); 

    function Custom_AddDocLibMenuItems(m, ctx) {
        AddECBMenuItems(m, ctx);

    function AddECBMenuItems(m, ctx) {
        var pageUrl = ctx.HttpRoot + "/_layouts/NY.ExportVersionHistory/ExportVersionHistory.aspx?ID=" + currentItemID + "&amp;List=" + ctx.listName;
        if (ctx.verEnabled) {
            CAMOpt(m, "Export Version History", "'" + pageUrl + "');", "/_layouts/images/NY.ExportVersionHistory/Excel_Small.png");


  1. getyournet // 28 April 2014 at 07:16  

    Thanks Nadeem!

    See also my solution with multiple implementations of Custom_AddListMenuItems and Custom_AddDocLibMenuItems:

My SharePoint CodePlex Projects

SharePoint 2010 Autocomplete Lookup Field

Export Version History Of SharePoint 2010 List Items to Microsoft Excel.