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

ClickToOpen and OnItemClick

4 Answers 173 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Josh Smith
Top achievements
Rank 1
Josh Smith asked on 22 Jan 2008, 04:48 PM
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.

4 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 23 Jan 2008, 03:14 PM
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
0
Josh Smith
Top achievements
Rank 1
answered on 23 Jan 2008, 10:49 PM
What if I wanted to execute server side code OnItemClicked?
0
Accepted
Veselin Vasilev
Telerik team
answered on 24 Jan 2008, 10:58 AM
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
0
Toan
Top achievements
Rank 1
answered on 12 Oct 2012, 08:37 PM
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>
Tags
Menu
Asked by
Josh Smith
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Josh Smith
Top achievements
Rank 1
Toan
Top achievements
Rank 1
Share this question
or