🎓 All Courses | 📚 Blazor WASM Syllabus
Stickipedia University
📋 Study this course on TaskLoco

While [Parameter] passes data from parent to child, EventCallback enables the reverse — a child component notifies its parent of events.

Defining EventCallback in a Child

// DeleteButton.razor
<button @onclick="HandleClick">Delete</button>

@code {
    [Parameter] public EventCallback OnDelete { get; set; }
    private async Task HandleClick() => await OnDelete.InvokeAsync();
}

EventCallback with Data

[Parameter] public EventCallback<Product> OnAddToCart { get; set; }

private async Task AddToCart()
{
    await OnAddToCart.InvokeAsync(Product);
}

Handling in the Parent

<ProductCard Product="item" OnAddToCart="HandleAddToCart" />

@code {
    private void HandleAddToCart(Product product)
    {
        cart.Add(product);
    }
}

EventCallback vs Action

  • EventCallback automatically calls StateHasChanged — UI re-renders automatically
  • Action does not — you must call StateHasChanged() manually
  • Always prefer EventCallback for component communication

YouTube • Top 10
Blazor WASM: EventCallback Child-to-Parent Communication
Tap to Watch ›
📸
Google Images • Top 10
Blazor WASM: EventCallback Child-to-Parent Communication
Tap to View ›

Reference:

Wikipedia: Observer Pattern

image for linkhttps://en.wikipedia.org/wiki/Observer_pattern

📚 Blazor WASM — Full Course Syllabus
📋 Study this course on TaskLoco

TaskLoco™ — The Sticky Note GOAT