Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Menu > Opening context menu on radbutton left click

Not answered Opening context menu on radbutton left click

Feed from this thread
  • USI avatar

    Posted on Jan 24, 2012 (permalink)

    Hi,

    Is it possible to open a RadContextMenu on RadButton left click only? I was only able to open the context menu with right click but not with left click.

    Thanks in advance,
    Michael Pinheiro

    Reply

  • Posted on Jan 24, 2012 (permalink)

    Hello,

    Try the following javascript on OnClientClicked event of RadButton.
    JS:
    function OnClientClicked(sender, args)
     {
        var contextMenu = $find("<%= RadMenu1.ClientID %>");
        contextMenu.show(args);
     }

    Thanks,
    Princy.

    Reply

  • Shukhrat Nekbaev avatar

    Posted on Mar 1, 2012 (permalink)

    Hi,
    <telerik:RadButton ID="btnAddComponent" runat="server" Text="Show items" AutoPostBack="false" OnClientClicked="addNewComponent" UseSubmitBehavior="false">
    </telerik:RadButton>
    <span onclick="javascript:showMenu(event);">Test open</span>

    and menu:
    <telerik:RadContextMenu ID="radCtxMenuNewPageComponent" runat="server" CausesValidation="true" ValidationGroup="editCurrentProjectContentElement" OnItemClick="radCtxMenuNewPageComponent_ItemClick">
        <Items>
            <telerik:RadMenuItem Text="Audio" />
            <telerik:RadMenuItem Text="Video" />
        </Items>
        <CollapseAnimation Type="none" />
    </telerik:RadContextMenu>

    following JS:

    function addNewComponent(sender, args) {
                showMenu(event);
            }
     
    function showMenu(e) {
        var contextMenu = $find("<%= radCtxMenuNewPageComponent.ClientID %>");
     
        if ((!e.relatedTarget) || (!$telerik.isDescendantOrSelf(contextMenu.get_element(), e.relatedTarget))) {
            contextMenu.show(e);
        }
     
        $telerik.cancelRawEvent(e);
    }

    so when RadButton is clicked it works in IE9 and latest Chrome (haven't tried anything else yet), but doesn't work in FF, in FF it complains on event object. In RadButton's click handler I tried to pass "args" also, then in IE9 context menu is displayed in top left corner, but doesn't work in FF. Provided span trigger works good.

    How do I get RadButton to trigger context menu so that it works in all browsers? Thank you!

    P.S.: using latest controls (2012.1.215.40)

    Reply

  • Peter Peter admin's avatar

    Posted on Mar 6, 2012 (permalink)

    Hi,

    The DOM event on clicking the RadButton is not passed to the event argument. Therefore, you cannot use this approach with RadButton. As a workaround, you can try the following:
    function addNewComponent(sender, args) {
               
                    var currentLocation = $telerik.getLocation(sender.get_element());
                    var contextMenu = $find("<%=radCtxMenuNewPageComponent.ClientID%>");
                    contextMenu.showAt(currentLocation.x, currentLocation.y + 22);  
              
            }


    Regards,
    Peter
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.

    Reply

  • Shukhrat Nekbaev avatar

    Posted on Mar 6, 2012 (permalink)

    Hi,

    yeah, I've implemented similar workaround already, thanks anyway!

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Menu > Opening context menu on radbutton left click
Related resources for "Opening context menu on radbutton left click"

[  ASP.NET Menu Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]