• Documentation

    Elanat Documentation
    The most important feature of Elanat is its add-ons-oriented structure. Add-ons-oriented structure allows you to create your own Add-ons without conflicting with Eanat core.

    WebForms Core Technology - 4.6 WASM Events

    4.6 WASM Events

    WASM Events allow an HTML event to invoke a method in a WebAssembly module through WebForms Core. The server defines the event using the WebForms class, while WebFormsJS handles the client-side WebAssembly invocation when the specified event occurs.

    The basic execution flow is:

    A WASM Event identifies the WebAssembly environment, the location of the WASM resource, the method to invoke, and optionally the arguments and an OutputPlace for the returned result.

    4.6.1 SetWasmEvent

    The SetWasmEvent method assigns a WebAssembly method to an HTML event.

    When the specified event occurs on WasmButton, WebFormsJS invokes the specified WebAssembly method.

    The method signature is:

    Parameter Description
    InputPlace The WPC expression identifying the HTML element on which the WASM Event is assigned.
    HtmlEvent The HTML event that triggers the WebAssembly method.
    WasmLanguage Identifies the WebAssembly execution type or language.
    WasmUrl The URL of the WebAssembly resource or its corresponding runtime resource, depending on the WASM execution type.
    MethodName The name of the method to invoke in the WebAssembly environment.
    Args An optional array of arguments passed to the WebAssembly method.
    OutputPlace An optional WPC expression identifying where the returned result is placed.

    Calling a Method with Arguments

    Arguments can be passed through the Args parameter.

    In this example, the values in the array are passed to MyClass.SetData when the button is clicked.

    The method name can include a class name. A period separates the class name from the method name:

    This makes it possible to address a method belonging to a specific class in the WebAssembly environment.

    4.6.2 WASM Event with OutputPlace

    SetWasmEvent also supports an OutputPlace parameter. This is useful when the WebAssembly method returns a value that should be placed into a specific HTML element.

    In this example, the result returned by MyClass.GetHtml is directed to the element identified by WasmHtmlOutput.

    The OutputPlace is optional. A WASM Event can therefore be used simply to invoke a WebAssembly method without specifying an output location.

    4.6.3 SetWasmEventListener

    The SetWasmEventListener method provides the EventListener form of WASM Event assignment.

    The method signature is:

    The parameters are equivalent to SetWasmEvent, except that the event is specified through HtmlEventListener.

    For example:

    The main distinction is therefore the event mechanism:

    Method Event Definition
    SetWasmEvent HtmlEvent
    SetWasmEventListener HtmlEventListener

    4.6.4 Removing a WASM Event

    The RemoveWasmEvent method removes a WASM Event assigned through SetWasmEvent.

    The method signature is:

    The method identifies the element and the HTML event from which the WASM Event assignment should be removed.

    4.6.5 Removing a WASM Event Listener

    The RemoveWasmEventListener method removes a WASM Event Listener assigned through SetWasmEventListener.

    The method signature is:

    As with the other Event APIs, the removal method does not require the WASM URL or method name. It identifies the event assignment through the target element and event definition.

    4.6.6 Set and Remove WASM Events

    The WASM Event API provides a corresponding removal method for each assignment mechanism:

    Assignment Method Removal Method
    SetWasmEvent RemoveWasmEvent
    SetWasmEventListener RemoveWasmEventListener

    For example, a WASM Event can be assigned and later removed:

    The listener-based form can be handled in the same way:

    4.6.7 WebAssembly Language and Runtime

    The WasmLanguage parameter identifies how WebFormsJS should handle the WebAssembly resource. WebForms Core provides predefined values through the WasmLanguage class, including values for C, C++, Rust, C#, and the .NET WebCIL environment.

    The exact loading and invocation process depends on the selected WebAssembly environment. For this reason, this section does not describe the complete WebAssembly architecture or runtime configuration.

    4.6.8 WASM Event and WebForms Core Commands

    A WebAssembly method can return a value that is subsequently processed by WebFormsJS. One particularly useful scenario is returning a WebForms Core response generated inside a WebAssembly environment.

    For example, a WebAssembly method can create a WebForms object and generate a response:

    The important point for WASM Events is that the WebAssembly method can become another source of WebForms Core output. WebFormsJS receives the returned value and processes it according to the WebForms Core execution model.

    4.6.9 WASM Event Example

    The following example demonstrates the basic use of SetWasmEvent without covering the complete WebAssembly project configuration.

    In the first event, clicking WasmEvent invokes MyClass.SetData with the specified arguments.

    In the second event, clicking WasmEventWithOutput invokes MyClass.GetHtml and directs its returned value to WasmHtmlOutput.

    The WebAssembly implementation itself is intentionally not covered here. A later dedicated section will explain WebAssembly in WebForms Core in detail, including the supported execution models, runtime loading, methods, communication, and integration with WebForms Core.

    4.6.10 WASM Events in the WebForms Core Architecture

    WASM Events extend the WebForms Core event model by allowing WebAssembly execution to be triggered from standard HTML events.

    When the WebAssembly method returns a WebForms Core response, the flow can continue through the same command execution model:

    This allows WebAssembly to participate in WebForms Core without changing the fundamental HTML and Action Control model.

    4.6.11 Summary

    • SetWasmEvent assigns a WebAssembly method to an HtmlEvent.
    • SetWasmEventListener assigns a WebAssembly method to an HtmlEventListener.
    • Both methods support a WASM language identifier, WASM URL, method name, optional arguments, and optional OutputPlace.
    • RemoveWasmEvent removes a WASM Event assigned through SetWasmEvent.
    • RemoveWasmEventListener removes a WASM Event Listener assigned through SetWasmEventListener.
    • A WebAssembly method can return a value that WebFormsJS processes according to the configured output behavior.
    • A WebAssembly method can also generate WebForms Core commands and return them as a WebForms Core response.

    WASM Events provide a direct event-driven bridge between standard HTML events and WebAssembly methods. The complete WebAssembly capabilities of WebForms Core will be documented separately.