Overview

DOM events can be assigned an event handler to execute code when the event is triggered:
@onsomeDOMevent="Delegate"

Example

<button @onclick="SaveEmployee">Save</button>
@code 
{
    private void SaveEmployee()
    {
        
    }
}

Default Event Arguments

Some events support event arguments. For example:

  • @onclick passes MouseEventArgs
  • @onkeydown passes KeyboardEventArgs

Example

<button @onclick="ShowLocation">Show</button>
@code 
{
    private void ShowLocation(MouseEventArgs e)
    {
    }
}

EventCallback

When an event occurs in a child Component, use EventCallback to trigger code to execute in the parent Component:

ChildComponent.razor

<button @onclick="TriggerCallbackToParent">Show</button>
@code
{
    [Parameter]
    public EventCallback<MouseEventArgs> TriggerCallbackToParent { get; set; }
}

ParentComponent.razor

<ChildComponent TriggerCallbackToParent="ShowPopup"></ChildComponent>
@code
{
    private void ShowPopup()
    {
        
    }
}