You are on page 1of 1

Chapter 6 General Blazor

we simply use the one and only method it has, InvokeAsync, which takes
the name of the JavaScript function as its first argument, and the rest of the
parameters will be the parameters passed in the JavaScript function. Do
note that you can also create an object array for passing the parameters
and always mind the return type of JavaScript function, so it is correct.
Everything is quite simple, and there is nothing to worry if you need to
access your old JavaScript libraries or the ones that may not be widely
available for Blazor.

UI Events
HTML elements have several events, some generic and some tag specific.
The good news is that you can use all of them directly in Blazor with no
JavaScript interactions.

Listing 6-3.  User interface events page

@page "/UIeventsPage"

<textarea @onpaste="@OnpasteTest"></textarea>
<video @onpause="@OnPauseTest"  ></video>
<p>@output</p>
@code {
    string output;
    void OnpasteTest()
    {
        output = "text pasted";
    }

    void OnPauseTest()
    {
         output = "Don't give up watching";
    }
}

116

You might also like