liveBook · Manning

onClick

As explained in Pro ASP.NET Core 7, Tenth Edition

The @onclick attribute is a Blazor event-handling directive attribute that binds a user-interface click event to a .NET method or expression.

The Blazor @onclick directive attribute binds a button click to a .NET method or expression. The component can use that handler to communicate with other components or update displayed data. section 10.2.2

Common uses in the SportsStore administration interface include:

...
<button class="btn btn-sm btn-danger" 
        @onclick="@(e => OrderSelected.InvokeAsync(o.OrderID))">
    @ButtonLabel
</button>
...

The order-table button passes the selected order ID to the OrderSelected callback when clicked. section 10.2.2

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Explains method and callback invocation through component examples, while deferring deeper Blazor treatment.
Examples
Shows order selection, data refresh, and product deletion in SportsStore administration components.
What you can do after
Apply Blazor’s @onclick directive to invoke component methods for order selection, refresh, or product deletion.
How it connects
Connects Blazor event handling with Razor components, .NET methods, and component callbacks.

Also explained in

Compare how 2 books explain onClick →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.