ClickToOpen and OnItemClick

5 posts, 1 answers
  1. Josh Smith
    Josh Smith avatar
    4 posts
    Member since:
    Apr 2006

    Posted 22 Jan 2008 Link to this post

    If I want a menu to open only when someone clicks on the menu, how do I access what is clicked on inside the menu?  When I try to use both of the properties OnItemClick is fired which causes a postback and ClickToOpen does not work properly.

    Thank you.
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 23 Jan 2008 Link to this post

    Hello Josh Smith,

    It is better to handle the ItemClick events on the client.

    Consider the following sample code:

    <telerik:RadMenu ID="RadMenu1" runat="server"  
                ClickToOpen="True" Flow="Horizontal"  
                OnClientItemClicking="beforeClientClick"


    <script type="text/javascript"
    function beforeClientClick(sender, eventArgs) 
        var item = eventArgs.get_item(); 
        if (item.get_parent() == sender) 
        { 
            //root item clicked 
        } 
        else 
        { 
            //child item clicked 
        }   
    </script> 

    Hope this helps

    Kind regards,
    Veskoni
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Josh Smith
    Josh Smith avatar
    4 posts
    Member since:
    Apr 2006

    Posted 23 Jan 2008 Link to this post

    What if I wanted to execute server side code OnItemClicked?
  5. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 24 Jan 2008 Link to this post

    Hello Josh Smith,

    Please take a look at the example I created for you and attached to this thread.
    It uses ItemClick server side event, ClickToOpen set to true and after the postback - the menu is expanded as needed.

    Hope this helps.

    Regards,
    Veskoni
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Toan
    Toan avatar
    1 posts
    Member since:
    Oct 2012

    Posted 12 Oct 2012 Link to this post

    I also wanted to do the same thing.  That is to show menu only on mouse click  and not on mouse over.  I played around with the suggestions above and this is what i came up with.  It seems to work.  Essentially, i have to override the behavior of the client mouse click event (OnClientItemClicking).
    <script type="text/javascript">
        function OnClientItemClicking(sender, eventArgs)
        {
            var radMenuItem = eventArgs.get_item();
     
            if (radMenuItem._hasItems) {
                radMenuItem.open();
                radMenuItem.focus();
     
                eventArgs.set_cancel(true);
            }
        }
    </script>
     
    <telerik:RadMenu ID="menuRoot" runat="server" ClickToOpen="true" OnClientItemClicking="OnClientItemClicking">
    </telerik:RadMenu>
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017