Opening context menu on radbutton left click

5 posts, 0 answers
  1. USI
    USI avatar
    26 posts
    Member since:
    Oct 2009

    Posted 24 Jan 2012 Link to this post

    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
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Jan 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shukhrat Nekbaev
    Shukhrat Nekbaev avatar
    73 posts
    Member since:
    Oct 2010

    Posted 01 Mar 2012 Link to this post

    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)
  5. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 06 Mar 2012 Link to this post

    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.
  6. Shukhrat Nekbaev
    Shukhrat Nekbaev avatar
    73 posts
    Member since:
    Oct 2010

    Posted 06 Mar 2012 Link to this post

    Hi,

    yeah, I've implemented similar workaround already, thanks anyway!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017