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=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:
Thank you to Pascal Van Vlaenderen for the information on this.
-
Paul Liebrand
-
ask?
-
Paul Liebrand
-
LeoJ
-
Paul Liebrand
-
Pascal Van Vlaenderen



