Live Chat Icon For mobile
Live Chat Icon

How is the onclick event of HTML element handled in Blazor?

Platform: Blazor| Category: Event handling

Blazor provides support for event handling of HTML element by referring a pointer to the function that is used to handle the event, For handling @onclick event of the HTML element, define a function/method in the @code section and then refer the delegate typed value to the @onclick attribute of the HTML element.

Refer to the following code sample.

<button class="btn btn-primary" @onclick="ButtonClick">Click</button>

@code {
         private void ButtonClick(MouseEventArgs args){
          Console.WriteLine(“ButtonClicked”)
         }
}

Here, the ButtonClick is the event handler function (delegate typed value) assigned to @onclick of the button (HTML element).

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.