New to Telerik UI for Blazor? Start a free 30-day trial

Handle Button OnClick in a Code-Behind File

Updated on Oct 19, 2026

Environment

ProductButton for Blazor
Version15.0.1 and above

Description

Handle the Telerik Button OnClick event from a C# code-behind file instead of declaring the event handler in the Razor markup.

Solution

Reference the Button with @ref and assign the EventCallback<MouseEventArgs> after the component reference becomes available. Use OnAfterRender and perform the assignment only during the first render.

Button.razor:

RAZOR
<TelerikButton @ref="@ButtonRef">
    Click Me
</TelerikButton>

Button.razor.cs:

CS
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Telerik.Blazor.Components;

public partial class Button
{
    private TelerikButton ButtonRef { get; set; } = default!;

    protected override void OnAfterRender(bool firstRender)
    {
        if (firstRender)
        {
            ButtonRef.OnClick = EventCallback.Factory.Create<MouseEventArgs>(
                this,
                OnButtonClick);
        }
    }

    private void OnButtonClick(MouseEventArgs args)
    {
        // Handle the button click.
    }
}

The OnClick event receives a MouseEventArgs argument. The handler can also be asynchronous. For more information, see EventCallback can be async.

See Also