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

open a radcontextmenu on left click of a radbutton

3 Answers 353 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Sigma
Top achievements
Rank 1
Sigma asked on 19 Oct 2012, 12:12 PM
hii,
How can i open a radcontextmenu on left click of a radbutton?


thanks...

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Oct 2012, 12:32 PM
Hi Sigma,

Try the following code snippet to achieve your scenario.

ASPX:
<telerik:RadButton ID="RadButton1" runat="server" Text="Show" OnClientClicked="OnClientClicked">
</telerik:RadButton>
<telerik:RadContextMenu ID="RadContextMenu1" runat="server"  >
     <Items>
          <telerik:RadMenuItem Text="RadMenuItem1">
          </telerik:RadMenuItem>
          <telerik:RadMenuItem Text="RadMenuItem2">
          </telerik:RadMenuItem>
          <telerik:RadMenuItem Text="RadMenuItem3">
          </telerik:RadMenuItem>
     </Items>
</telerik:RadContextMenu>

JS:
<script type="text/javascript">
    function OnClientClicked(sender, args) {
        var contextMenu = $find("<%= RadContextMenu1.ClientID %>");
        contextMenu.show(args);
    }
</script>

Regards,
Shinu.
0
Sam
Top achievements
Rank 1
answered on 09 Nov 2017, 05:01 PM

I had to add this:

<script type="text/javascript">
    function OnClientClicked(sender, args) {
        var contextMenu = $find("<%= RadContextMenu1.ClientID %>");
        contextMenu.show(args);
        $telerik.cancelRawEvent(event);
    }
</script>

 

I'm attaching to a div.  The above code shows the context menu...

How do I hide the menu when user clicks elsewhere or when user blurs off the context menu?

0
Marin Bratanov
Telerik team
answered on 10 Nov 2017, 02:47 PM

Hi Sam,

You can call the client-side hide() method of the RadContextMenu when you want it to hide: https://docs.telerik.com/devtools/aspnet-ajax/controls/menu/client-side-programming/objects/radmenu-and-radcontextmenu-objects#radcontextmenu-specific-api.

To this end you can attach event handlers to the page (e.g., click for the body, mouseover for the body) and check whether the event originates from the menu, in a fashion similar to this thread: https://www.telerik.com/forums/how-to-show-hide-menu-on-mouseover-and-mouseout.

Regards,

Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Menu
Asked by
Sigma
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sam
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or