+1-888-365-2779
Try Now
More in this section

Forums / Designing with Sitefinity / Show menu only at level 2

Show menu only at level 2

8 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    07 Nov 2007
    Link to this post
    Hello telerik,

    Another menu question in the following situation:

    I've a navigation menu on top of my page. This navigation menu show only 1 level of menu items. If there is also a level 2 with menu items, they are set invisible for this menu.

    Know when I click on a level 1 menu-item I want another menu control somewhere else on the page to show these menu-item(s), based on the 'paren' menu-item that is currently selected.

    I tried to use the StartFromCurrentNode property but that didn't work.

    How could I achieve this?

    Thanks,
    Daniel
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    08 Nov 2007
    Link to this post
    Hello Daniel,

    You can have a look at the following online example. It demonstrates how one menu can be used to populate another i.e. when you select an item from the first menu, its children create the contents of the second menu.

    Hope this helps.

    Best wishes,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    09 Nov 2007
    Link to this post
    Hi Pepi,

    The 2 menu's are not on the same page, as in the example.
    I've created 2 custom sitemenu's (based on the ones from Sitefinity) that are placed inside 2 different ContentPlaceHolders.

    So the 1 ContentPlaceHolder contains my main menu, and the 2 ContentPlaceHolder contains the 2 menu.

    If the user clicks a menuitem on the main menu (1) then the items of the second menu should be visible ONLY if this menuitem is a 'level 1' menuitem.

    Could this be done in code you think?

    Hope you can give me some advice.

    Thanks!
    Daniel
  4. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    09 Nov 2007
    Link to this post
    Hello Daniel,

    The easiest solution is to register the User Controls with the Menus directly in your .master page and implement the logic from the online example in the code behind of the .master page i.e. the desired functionality will be realized programatically through Visual Studio, not with drag and drop through Sitefinity interface. Here is an example for referencing a user control within a Web page:

    <%@ Register tagprefix="uc1"  
        tagname="CalendarUserControl"  
        src="~/CalendarUserControl.ascx" %> 

    You could find more information on this matter in MSDN library.

    Hope this is helpful for you.

    Sincerely yours,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    12 Nov 2007
    Link to this post
    Hi Pepi,

    My CustomSiteMenu is inside a ContentPlaceHolder. How should I setup the reference to this control? If I do a 'FindControl' inside my ContentPlaceHolder the 'Controls' Collection = 0.

    I can't get the right reference...

    Daniel
  6. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    13 Nov 2007
    Link to this post
    Hi Daniel,

    In the attachment you could find an example how to reference a User Control in a page.

    Hope this helps.

    Greetings,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    13 Nov 2007
    Link to this post
    Hi Pepi,

    Thanks for the example.
    I didn't understand that I had to include the CustomSiteMenu inside the ContentPlaceHolder in the MasterPage, because I did this inside Sitefinity.

    So, I created the reference as in your example. Now I want to capture the ItemClick event from this menu. I did try something as follows:

    1  protected void Page_Load(object sender, EventArgs e)  
    2     {  
    3         RadMenu m = (RadMenu)((CustomSiteMenu)this.csm).FindControl("menubar");  
    4         m.ItemClick += new RadMenuEventHandler(m_ItemClick);  
    5     }  
    6  
    7     void m_ItemClick(object sender, RadMenuEventArgs e)  
    8     {  
    9         FilterMenu(e.Item);  
    10     }  
    11  

    But this didn't work.
    Where should I initialize the RadMenuEventHandler?

    Greetings,
    Daniel
  8. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    13 Nov 2007
    Link to this post
    Hi Daniel,

    First of all SiteMenu has a property Menu that represents a reference to the wrapped RadMenu control and can be used to access properties which are not directly available. So you could use this.cms.Menu instead of  (RadMenu)((CustomSiteMenu)this.csm).FindControl("menubar") to access RadMenu control.

    As for initializing RadMenuEventHandler, it is better to implement this in OnInit method. For example:

    protected override void OnInit(EventArgs e) 
        { 
            base.OnInit(e); 
            this.cms.Menu.ItemClick += new Telerik.WebControls.RadMenuEventHandler(Menu_ItemClick); 
        } 

    Also, the reason for the event firing problem is that most probably you are setting the NavigateUrl property. In this case, when you click on an item, you will be immediately redirected and the item will never get the chance to fire a server event. If you want to have the ItemClick event fired and navigate to another page, I suggest you do not set the NavigateUrl property but use Response.Redirect for example. You can store the actual URL in the Value property of the menu item. For example:

    protected void Menu_ItemClick(object sender, Telerik.WebControls.RadMenuEventArgs e)   
    {   
     ... 
     Response.Redirect(e.Item.Value);   
    }  

    Hope this is helpful.

    All the best,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
8 posts, 0 answered