Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a scenario where I need to create an application page that is installed to the ECB menu of a specific list only. Is this possible? or is the only way to do it associating the elements file with a list type e.g. task list?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

Yes it is possible to do that: create ECB items menu only for a list....and even better decide at runtime how many items to put in the ECB menu. For this you need javascript skills.

SharePoint give us some hooks to add custom ECB items using javascript. This hook is the js function: Custom_AddListMenuItems(m, ctx). But the problem is how to add dynamic items in the ECB right ? The solution I've used was to implement a synchronous Ajax call to a custom aspx which returns a xml with items and their actions. Here is the code:

<script language="javascript">

function Custom_AddDocLibMenuItems(m, ctx)
{    
  //debugger;

  var request;
  var url = ctx.HttpRoot + 
      "/_layouts/GetCommands.aspx?ListID=" + ctx.listName + 
      "&ItemID=" + currentItemID + 
      "&UserId=" + ctx.CurrentUserId + 
      "&DateTime=" + Date();

   if ( window.XMLHttpRequest )
   {
      request = new XMLHttpRequest();
      request.open("GET", url, false);
      request.send(null);
   }
   else if ( window.ActiveXObject )
   {
      request = new ActiveXObject("Microsoft.XMLHTTP");
      if ( request )
      {
         request.open("GET", url, false);
         request.send(); 
      }
   }

   if ( request )
   {   
      var commands = request.responseXML.getElementsByTagName("Command");
      // for each command found in the returned XML, extract the name, 
      // image Url and script, and a new menu item with these properties
      for ( var i = 0; i < commands.length; i++ )
      {
         var cmdName = commands[i].getElementsByTagName(
            "Name")[0].firstChild.nodeValue;
         var imageUrl = commands[i].getElementsByTagName(
            "ImageUrl")[0].firstChild.nodeValue;
         var js = commands[i].getElementsByTagName(
            "Script")[0].firstChild.nodeValue;
         var addSep = commands[i].getElementsByTagName(
            "AddSep")[0].firstChild.nodeValue;

         CAMOpt(m, cmdName, js, imageUrl);

         if (addSep == "True")
            CAMSep(m);
      }

      // if at least one command was actually added, add a separator
      if ( commands.length > 0 )
         CAMSep(m);
   }

   // returning false makes SharePoint render the rest of the standard menu
   return false;   
}

function Custom_AddListMenuItems(m, ctx)
{
    Custom_AddDocLibMenuItems(m, ctx);
}
</script>

This script must be placed in a webpart next to the list webpart (in a Content Editor Web Part for ex.)

The idea is not mine, here is the original article. Hope this will help.

share|improve this answer
    
You're right, using JavaScript it's possible. –  Wictor Wilen MCA MCM MVP Oct 14 '09 at 6:19
    
Please take into account this article on jQuery: the SharePoint band aid. This kind of stuff won't upgrade to SP2010 as the UI is completely different. wss.made4the.net/archive/2009/02/23/… –  Anonymous Oct 14 '09 at 6:37
    
How do you know that ? And I'm not agree with that article at all. Using javascript/jquery it is and will be a great way to improve/customize SharePoint controls. Some sp controls simply can't be changed. So "this kind of stuff" was available since SP2003, it is for SP2007 and I'm sure will be too for SP2010. Adding js is not a danger, don't be afraid we are living in a web world. –  Ovidiu Becheş-Puia Oct 14 '09 at 12:38
add comment

It must be attached to a list template (if you are using the server side features), that has a specific id. I recommend that you create a feature with a hidden list template and list instance and then attaches your ECB to that list template.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.