New to Telerik UI for ASP.NET Core? Download free 30-day trial

Events

The Telerik UI ContextMenu for ASP.NET Core exposes a number of events that allow you to control and customize the UI component.

Handling by Handler Names

The following example demonstrates how to subscribe to events by a handler name.

@(Html.Kendo().ContextMenu()
        .Name("menu")
        .Target("body")
        .Events(e => e
            .Open("menu_open")
            .Close("menu_close")
            .Select("onSelect)
        )
)
    <kendo-contextmenu name="contextmenu" target="body" 
        on-open="menu_open"
        on-close="menu_close"
        on-select="onSelect">
    </kendo-contextmenu>
    <script>
        function openMenu(){
            // Handle the open event.
        }

        function closeMenu(){
            // Handle the close event.
        }

        function onSelect(){
            // Handle the select event.
        }
    </script>

Handling by Template Delegates

The following example demonstrates how to subscribe to events by a template delegate.

@(Html.Kendo().ContextMenu()
    .Name("menu")
    .Target("body")
    .Events(e => e
        .Open(@<text>
            function() {
                // Handle the open event inline.
            }
        </text>)
        .Close(@<text>
            function() {
                // Handle the close event inline.
            }
        </text>)
    )
)

Handling by HTML Attributes

The following example demonstrates how to subscribe to the select event of a single Context Menu item.

@(Html.Kendo().ContextMenu()
    .Name("menu")
    .Target("body")
    .Items(items =>
    {
        items.Add().Text("First Item");
        items.Add().Text("Second Item").HtmlAttributes(new { @onclick = "alert('select');" });
    })
)

Next Steps

See Also

In this article