This is a migrated thread and some comments may be shown as answers.

wrap prometheus menu in a custom server control

10 Answers 147 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Beth Krawczuk
Top achievements
Rank 1
Beth Krawczuk asked on 25 Feb 2008, 10:58 PM

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

Sort by
0
Atanas Korchev
Telerik team
answered on 26 Feb 2008, 08:21 AM
Hello Beth Krawczuk,

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
0
Beth Krawczuk
Top achievements
Rank 1
answered on 27 Feb 2008, 12:01 AM
Actually I didn't explain that well,
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

0
Beth Krawczuk
Top achievements
Rank 1
answered on 27 Feb 2008, 12:01 AM

0
Beth Krawczuk
Top achievements
Rank 1
answered on 27 Feb 2008, 12:01 AM

0
Beth Krawczuk
Top achievements
Rank 1
answered on 27 Feb 2008, 12:01 AM

0
Beth Krawczuk
Top achievements
Rank 1
answered on 27 Feb 2008, 12:01 AM

0
Beth Krawczuk
Top achievements
Rank 1
answered on 27 Feb 2008, 12:01 AM

0
Beth Krawczuk
Top achievements
Rank 1
answered on 27 Feb 2008, 12:01 AM

Oops, I'm not sure why this posted a bunch of times.
Sorry,
Beth

0
Accepted
Atanas Korchev
Telerik team
answered on 27 Feb 2008, 07:56 AM
Hello Beth Krawczuk,

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
0
Beth Krawczuk
Top achievements
Rank 1
answered on 27 Feb 2008, 03:52 PM
You guys ROCK!
Thank you very much,
Beth
Tags
Menu
Asked by
Beth Krawczuk
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Beth Krawczuk
Top achievements
Rank 1
Share this question
or