Paul Liebrand's Weblog

Welcome to my blog mainly about SharePoint

Skip to: Content | Sidebar | Footer

Google Search
Custom Search

CustomAction, NewMenu and mysterious blank control

14 July, 2008 (14:42) | SharePoint | By: Paul Liebrand

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:

NewMenuMissing

The elements.xml of this feature looks like this:

   1: <CustomAction GroupId="NewMenu"
   2:               Location="Microsoft.SharePoint.StandardMenu"
   3:               ControlAssembly="NewMenuSample, Version=1.0.0.0, 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;
   4:
   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";
  15:
  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:

FullMenu

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

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

  • Pascal Van Vlaenderen

    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 :)

    Greetings,

    Pascal

    PS: Thanks for mentioning me :)

  • Pascal Van Vlaenderen

    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 :)

    Greetings,

    Pascal

    PS: Thanks for mentioning me :)

  • Pascal Van Vlaenderen

    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 :)

    Greetings,

    Pascal

    PS: Thanks for mentioning me :)

  • http://www.paulliebrand.com Paul Liebrand

    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!

  • http://www.paulliebrand.com Paul Liebrand

    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!

  • http://liebrand.wordpress.com liebrand

    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!

  • LeoJ

    Regarding your response here
    http://forums.msdn.microsoft.com/en-US/sharepointcustomization/thread/95aaa5dc-7656-4d8b-bdb7-b0e4122a054c/

    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!!

  • LeoJ

    Regarding your response here
    http://forums.msdn.microsoft.com/en-US/sharepointcustomization/thread/95aaa5dc-7656-4d8b-bdb7-b0e4122a054c/

    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!!

  • LeoJ

    Regarding your response here
    http://forums.msdn.microsoft.com/en-US/sharepointcustomization/thread/95aaa5dc-7656-4d8b-bdb7-b0e4122a054c/

    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!!

  • http://www.paulliebrand.com Paul Liebrand

    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.

  • http://www.paulliebrand.com Paul Liebrand

    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.

  • http://liebrand.wordpress.com liebrand

    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.

  • ask?

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

  • ask?

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

  • ask?

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

  • http://www.paulliebrand.com Paul Liebrand

    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.

  • http://www.paulliebrand.com Paul Liebrand

    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.

  • http://liebrand.wordpress.com liebrand

    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.