close top level menu item after child menu selection

4 posts, 0 answers
  1. Mark
    Mark avatar
    132 posts
    Member since:
    Feb 2008

    Posted 26 Nov 2008 Link to this post

    Hi,
    i create my menu server-side (all with navigateurl).

    I set my top level menu to be ClickToOpen=True, but i cant seem to make the top level menu close when i have selected a child menu.

    It stays open and i have to click somewhere on the page to close it.

    Is there any way (code or javascript) to close the top level menu when one of its child menus have been selected ??

    Many Thanks
    Mark
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Nov 2008 Link to this post

    Hi Mark,

    You can use the following function to close the RadMenuitem on clicking on item. Call the function on "OnClientItemClicked" event of RadMenu.

    JavaScript:
    <script type="text/javascript">  
    function OnClientItemClicked(sender, eventArgs)  
    {  
        if (eventArgs.get_item().get_parent() !=  sender)  
        {  
            var text= eventArgs.get_item().get_parent().get_text();  
            var menu = $find("<%= RadMenu1.ClientID %>");  
            var item = menu.findItemByText(text);  
            if (item)  
            {  
                item.close();  
            }  
        }  
    }  
    </script> 

    Thanks,
    Princy.
  3. Mark
    Mark avatar
    132 posts
    Member since:
    Feb 2008

    Posted 27 Nov 2008 Link to this post

    Hi,thanks for the reply.

    However,
    i am creating the menu items server-side.

    for the child menus i use

    childmenu.Attributes.Add("OnClick", "OnClientItemClicked()")

    but this is not firing in the javascript

     

    if

    (eventArgs.get_item().get_parent() != sender)


    What do i pass to the function ? (trued below but did'nt work )
    childmenu.Attributes.Add("OnClick", "OnClientItemClicked(" & childmenu.ClientID & ")")

    Any ideas please ?
    Thanks
    Mark

     

  4. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 28 Nov 2008 Link to this post

    Hi Mark,

    To subscribe to the OnClientItemClicked client-side event you need to do it like this:

    RadMenu1.OnClientItemClicked = "OnClientItemClickedHandler";


    I could not reproduce the problem that you describe. Can you paste some relevant code here please?


    Kind regards,
    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top