
Hi,
I need to wrap the prometheus menu control in a custom server control so that developers have limited control over changing styles, features, etc.
How would I go about creating the equivalent of this:
<telerik:radmenu id="mainRadMenu" runat="server" enableembeddedskins="false" enabletheming="true">
<Items>
<telerik:RadMenuItem Text="About us" AccessKey="U">
<Items>
<telerik:RadMenuItem Text="Mission Statement">
</telerik:RadMenuItem>
<telerik:RadMenuItem Text="Strategic Plan">
</telerik:RadMenuItem>
<telerik:RadMenuItem Text="Executive Bios">
</telerik:RadMenuItem>
<telerik:RadMenuItem Text="Contact Us">
</telerik:RadMenuItem>
</Items>
</telerik:RadMenuItem>
</Items>
</telerik:radmenu>
This is as far as I’ve gotten (I’m stuck on creating the internal “telerik:RadMenuItem”s:
[DefaultProperty("Text")]
[ToolboxData("<{0}:LISMenu runat=server></{0}:LISMenu>")]
public class LISMenu : Telerik.Web.UI.RadMenu
{
protected void LISMenu_Init(object sender, System.EventArgs e)
{
base.EnableEmbeddedSkins = false;
base.EnableTheming = true;
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
base.Render(writer);
}
}
Thank you so much for your help,
Beth
10 Answers, 1 is accepted
You can instantiate menu items in the OnInit or OnLoad methods (you need to override them).
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
base.EnableEmbeddedSkins = true;
base.EnableTheming = true;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!Page.IsPostBack)
{
RadMenuItem item = new RadMenuItem();
Items.Add(item);
}
}
Regards,
Albert
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

I'm trying to create a custom control that looks like this example:
<myCtrl:MyMenu id="mainMyMenu" runat="server">
<MainMenuItem Text=” Main menu item 1”></MainMenuItem>
<MainMenuItem Text=” Main menu item 2”></MainMenuItem>
<MainMenuItem Text=” Main menu item 3”>
<SubMenuItem Text=”Sub menu item 1”></SubMenuItem>
</MainMenuItem>
</ myCtrl:MyMenu>
So I'm not sure how to expose the "<Items>" and the "<telerik:RadMenuItem" properties or child controls so that I can define them and leave little left for the developer.
Thank you so much for your time,
Beth






Oops, I'm not sure why this posted a bunch of times.
Sorry,
Beth
The Items property of the menu is public so it should be already exposed. You can also create a new property which can hold your items (if you plan to inherit the RadMenuItemCollection class). In that case you should also override a few other methods. Here is a quick code snippet:
public class MyRadMenuItemCollection : RadMenuItemCollection |
{ |
public MyRadMenuItemCollection (Control parent) : base(parent) { } |
public new MyRadMenuItem this[int index] |
{ |
get |
{ |
return (MyRadMenuItem) base[index]; |
} |
set |
{ |
base[index] = value; |
} |
} |
} |
public class MyRadMenuItem : RadMenuItem |
{ |
} |
public class MyRadMenu : RadMenu |
{ |
protected internal override ControlItem CreateItem() |
{ |
return new MyRadMenuItem(); |
} |
protected override ControlItemCollection CreateChildItemCollection() |
{ |
return new MyRadMenuItemCollection(this); |
} |
[DefaultValue(null)] |
[MergableProperty(false)] |
[PersistenceMode(PersistenceMode.InnerProperty)] |
public MyRadMenuItemCollection MyItems |
{ |
get |
{ |
return (MyRadMenuItemCollection) base.Items; |
} |
} |
} |
Regards,
Albert
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

Thank you very much,
Beth