Community & Support
Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Menu > Firing context menu on table cells
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered Firing context menu on table cells

Feed from this thread
  • terrysmith Intermediate avatar

    Posted on Nov 15, 2006 (permalink)

    Hi,

    I need to show the r.a.d.Menu as a context menu on table cells. The table involved is an HTML table and not a telerik table. Showing the menu on a left-click works fine but is not what I need. During a right-click the browser's context window displays. All of the examples of using this control that I've seen either tie it to a specific control (and often that it a teleric control).

    How can I handle this situation? To explain where I'm coming from my end goal is to dynamically fill-out the context menu using Ajax with different items based on which cell the user right-clicked on. I think I can handle the Ajax portion if I can just get the right-click to work. I know that I could change the document.contextmenu to affect the whole page, but I'm trying not to do that.

    Thank you,
    Terry

  • INACTIVE_Rumen INACTIVE_Rumen admin's avatar

    Posted on Nov 15, 2006 (permalink)

    Hello Terry,

    We have a nice online example (r.a.d.menu as a context menu for r.a.d.grid - the grid renders as Html tables). Basically, when you right-click the button, you run your javascript code showing the context menu (Show / ShowAt methods) and then the browser takes over showing its own menu.

    In order to prevent this, you need to cancel the bubbling of the event. Here is some sample code for that:

    ...
    function RowContextMenu(index, e)
    {
        var menu = <%= RadMenu1.ClientID %>;
        document.getElementById("radGridClickedRowIndex").value = index;
        menu.Show(e);
        e.cancelBubble = true;  // IE
        if (e.stopPropagation)  // FireFox/ Gecko
        {
            e.stopPropagation();
        }
    }

    ...

    "e" refers to the browser event arguments. You can take a look at our online example here:

    ...
    http://www.telerik.com/demos/aspnet/Controls/Examples/Integration/GridAndMenu/DefaultCS.aspx
    ...

    All the best,
    Rumen Stankov (MCSD.NET)
    the telerik team

  • terrysmith Intermediate avatar

    Posted on Nov 16, 2006 (permalink)

    Thank you for you help. The problem I'm having is that when I right-click a table cell the Javascript function in for the onclick event never gets called. It does get called on a left-click. I've seen your online example before as well as others on the internet using the cancelBubble and stopPropagation, but there must be something else I'm missing since the browser's context menu is taking over before my function is even called.

    Thanks,
    Terry

  • INACTIVE_Rumen INACTIVE_Rumen admin's avatar

    Posted on Nov 16, 2006 (permalink)

    Hi Terry,

    Could you please open a support ticket with a small subset of your project reproducing this issue? It seems that we are missing important details in your setup and cannot reproduce the problem you are having.

    Sincerely yours,
    Rumen Stankov (MCSD.NET)
    the telerik team

  • terrysmith Intermediate avatar

    Posted on Nov 16, 2006 (permalink)

    I figured out I needed to use the oncontextmenu event instead of trying to determine which mouse button was pressed inside of the onclick event.

    Stupid me...

    Thanks,
    Terry

  • terrysmith Intermediate avatar

    Posted on Nov 16, 2006 (permalink)

    I figured out I needed to use the oncontextmenu event instead of trying to determine which mouse button was pressed inside of the onclick event.

    Stupid me...

    Thanks,
    Terry

  • INACTIVE_Rumen INACTIVE_Rumen admin's avatar

    Posted on Nov 16, 2006 (permalink)

    Hello Terry,

    We are glad that you've managed to find a solution for this problem - oncontextmenu is indeed much easier to use (compared to click and then checking the brwoser eventArgs for the button pressed).

    Does this solve the Atlas / context menu problem that you were having in this forums thread?
    http://www.telerik.com/community/forums/thread/b311D-khkba.aspx

    Best wishes,
    Rumen Stankov (MCSD.NET)
    the telerik team

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Menu > Firing context menu on table cells