wrap prometheus menu in a custom server control

11 posts, 1 answers
  1. Beth Krawczuk
    Beth Krawczuk avatar
    26 posts
    Member since:
    Feb 2008

    Posted 25 Feb 2008 Link to this post

    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

  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 26 Feb 2008 Link to this post

    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
  3. Beth Krawczuk
    Beth Krawczuk avatar
    26 posts
    Member since:
    Feb 2008

    Posted 26 Feb 2008 Link to this post

    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

  4. Beth Krawczuk
    Beth Krawczuk avatar
    26 posts
    Member since:
    Feb 2008

    Posted 26 Feb 2008 Link to this post

  5. Beth Krawczuk
    Beth Krawczuk avatar
    26 posts
    Member since:
    Feb 2008

    Posted 26 Feb 2008 Link to this post

  6. Beth Krawczuk
    Beth Krawczuk avatar
    26 posts
    Member since:
    Feb 2008

    Posted 26 Feb 2008 Link to this post

  7. Beth Krawczuk
    Beth Krawczuk avatar
    26 posts
    Member since:
    Feb 2008

    Posted 26 Feb 2008 Link to this post

  8. Beth Krawczuk
    Beth Krawczuk avatar
    26 posts
    Member since:
    Feb 2008

    Posted 26 Feb 2008 Link to this post

  9. Beth Krawczuk
    Beth Krawczuk avatar
    26 posts
    Member since:
    Feb 2008

    Posted 26 Feb 2008 Link to this post

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

  10. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 27 Feb 2008 Link to this post

    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
  11. Beth Krawczuk
    Beth Krawczuk avatar
    26 posts
    Member since:
    Feb 2008

    Posted 27 Feb 2008 Link to this post

    You guys ROCK!
    Thank you very much,
    Beth
Back to Top