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

Opening context menu on radbutton left click

4 Answers 291 Views
Menu
This is a migrated thread and some comments may be shown as answers.
USI
Top achievements
Rank 1
USI asked on 24 Jan 2012, 12:36 PM
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

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Jan 2012, 01:36 PM
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.
0
Shukhrat Nekbaev
Top achievements
Rank 1
answered on 01 Mar 2012, 04:08 PM
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)
0
Peter
Telerik team
answered on 06 Mar 2012, 11:20 AM
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.
0
Shukhrat Nekbaev
Top achievements
Rank 1
answered on 06 Mar 2012, 11:21 AM
Hi,

yeah, I've implemented similar workaround already, thanks anyway!
Tags
Menu
Asked by
USI
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Shukhrat Nekbaev
Top achievements
Rank 1
Peter
Telerik team
Share this question
or