Paul Liebrand’s Weblog

Welcome to my blog mainly about SharePoint

CustomAction, NewMenu and mysterious blank control

As many SharePoint developers know the toolbars are very customizable via features. However, if you ever tried to add a custom control too the NewMenu you may have been plagued by the mysterious blank control:


The elements.xml of this feature looks like this:

   1: <CustomAction GroupId="NewMenu"
   2:               Location="Microsoft.SharePoint.StandardMenu"
   3:               ControlAssembly="NewMenuSample, Version=, Culture=neutral, PublicKeyToken=9860eb616e81cf1b"
   4:               ControlClass="NewMenuSample.SampleNewMenuItem"
   5:               RegistrationId="101"
   6:               RegistrationType="List"
   7:               >
   8: </CustomAction>

And the actual code for the sample is pretty straightforward:

   1: using System;
   2: using System.Web.UI.WebControls;
   3: using Microsoft.SharePoint.WebControls;
   5: namespace NewMenuSample
   6: {
   7:     public class SampleNewMenuItem : WebControl
   8:     {
   9:         protected override void CreateChildControls()
  10:         {
  11:             MenuItemTemplate menu = new MenuItemTemplate();
  12:             menu.ID = "SampleMenu";
  13:             menu.Text = "Menu Item 1";
  14:             menu.Description = "Menu Item 1 Description";
  16:             this.Controls.Add(menu);
  17:         }
  18:     }
  19: }

It turns out that the problem lies in the CSS style being applied to the the elements causing the NewMenu items to be wrapped in a <SPAN> tag.

You can resolve this issue by simply adding the following to your class:

   1: protected override void Render(System.Web.UI.HtmlTextWriter writer)
   2: {
   3:     RenderChildren(writer);
   4: }

And then your custom menu item will start working as expected:


Thank you to Pascal Van Vlaenderen for the information on this.


July 14, 2008 - Posted by | SharePoint |


  1. You’re very welcome 🙂

    I just noticed you had a problem with it, probably registering the control as safe control. I forgot to say that.

    You shouldn’t forget the Javascript fixup if you want the submenus to behave nicely aswell 🙂



    PS: Thanks for mentioning me 🙂

    Comment by Pascal Van Vlaenderen | July 15, 2008 | Reply

  2. Actually the problem I experience was, embarrassingly, I did not have my class set as “public”. Yes — the javascript is completely necessary for submenus (I figured the post to your blog would be sufficient enough for people to find).

    Thank you again!

    Comment by liebrand | July 15, 2008 | Reply

  3. Regarding your response here

    After i removed the and run iisreset, And my entire menu gone…. even action, setting.. so i try to put this back, save it and iisreset again. It still no luck as menu still gone.. And one thing is nice which is i had backup the DefaultTemplates.ascx as you recommend. I used this to do the recover and it was back to normal. So.. do you know what is the problem….? Thanks in advance!!

    Comment by LeoJ | August 7, 2008 | Reply

  4. LeoJ — Sorry about the long delay in response. Your message got hung up in the WordPress spam system. If you could replicate the problem, perhaps you could show me the source of your new controltemplate which would help me understand why it may not be working.

    Comment by liebrand | September 11, 2008 | Reply

  5. Can you add controls (textbox, button,..) in MenuItemTemplate?.

    Comment by ask? | October 8, 2008 | Reply

  6. To the best of my knowledge, you cannot add custom controls to the MenuItemTemplate. However, you could probably create your own toolbar controltemplate and make it do whatever you want. This might be more effort than it is worth though. I’ll keep my eyes out to see if someone else has figured this out.

    Comment by liebrand | October 8, 2008 | Reply

Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: