• 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.3 Method Events

    4.3 Method Events

    Method Event allows an HTML event to invoke a JavaScript method through WebForms Core. Instead of writing a JavaScript event handler manually, the server can assign a method to an HTML event by using the WebForms class.

    This creates a direct execution path from an HTML event to a client-side method:

    HTML Event → WebFormsJS → JavaScript Method

    WebForms Core provides two forms of method invocation for events:

    • Method Event, for invoking a JavaScript method available directly.
    • Module Method Event, for invoking a method provided by a loaded JavaScript module.

    Both forms support regular HTML events and EventListener-based events.

    4.3.1 Method Event

    The SetMethodEvent method assigns a JavaScript method to an HTML event on the selected element.

    When the Button1 element receives the specified event, WebFormsJS invokes the method named showMessage.

    The method signature is:

    Parameter Description
    InputPlace The WPC expression identifying the HTML element on which the event is assigned.
    HtmlEvent The HTML event, such as HtmlEvent.OnClick or HtmlEvent.OnChange.
    MethodName The name of the JavaScript method to invoke.
    Args An optional array of arguments passed to the method.

    Arguments

    Arguments can be supplied through the optional Args parameter.

    The argument values are encoded into the Action Control and WebFormsJS uses them when invoking the method. Using object[] allows different value types to be supplied as method arguments.

    4.3.2 Method Event Listener

    SetMethodEventListener provides the EventListener form of Method Event.

    Its signature is:

    The difference between SetMethodEvent and SetMethodEventListener is the type of event definition they receive. The first uses HtmlEvent, while the second uses HtmlEventListener.

    WebForms Core distinguishes these two event mechanisms because they can have different execution requirements. In particular, the Event section supports dynamic arguments only once. When arguments need to be evaluated dynamically at the moment the event occurs, the corresponding EventListener method should be used.

    This distinction is important when an argument is not a fixed value, but is obtained from the current browser state or another dynamic source.

    4.3.3 Module Method Event

    Module Method Event extends the Method Event mechanism to methods provided by JavaScript modules.

    The server can assign a module method to an HTML event with SetModuleMethodEvent.

    The following code is an example of a JavaScript module.

    The method signature is:

    The parameters have the same general structure as SetMethodEvent. The important difference is that the specified method is resolved as a module method rather than as a regular method.

    Note: Before invoking methods from a JavaScript module, the module must first be loaded with LoadModule. The method names that can be used are specified in the second parameter. If the method name is not provided, all methods are called.

    WebForms Core also provides module management methods such as LoadModule, UnloadModule, and DeleteModuleMethod. This allows JavaScript modules and their methods to participate in the same server-orchestrated execution model.

    Module Method Event Listener

    The SetModuleMethodEventListener method provides the listener-based form.

    Its signature is:

    As with Method Events, the EventListener form is useful when the event must support dynamic argument evaluation at the moment of execution.

    4.3.4 Method Event vs Module Method Event

    Method Execution Target Event Type Arguments
    SetMethodEvent JavaScript method HtmlEvent Optional object[]
    SetMethodEventListener JavaScript method HtmlEventListener Optional object[]
    SetModuleMethodEvent Module method HtmlEvent Optional object[]
    SetModuleMethodEventListener Module method HtmlEventListener Optional object[]

    The distinction can therefore be summarized as follows:

    • MethodEvent selects a regular JavaScript method.
    • ModuleMethodEvent selects a method belonging to the module execution system.
    • The Event form uses an HTML event definition.
    • The EventListener form uses an event-listener definition and is intended for momentary dynamic argument evaluation.

    4.3.5 Removing Method Events

    Every Method Event assignment has a corresponding removal method.

    Remove Method Event

    The signature is:

    This identifies the element, event, and method that should be removed.

    Remove Method Event Listener

    The signature is:

    Remove Module Method Event

    The signature is:

    Remove Module Method Event Listener

    The signature is:

    The four removal methods correspond directly to the four assignment methods. Their Action Control identifiers are different from the assignment identifiers, allowing WebFormsJS to remove the specified event-method association.

    4.3.6 Complete Example

    The following example assigns both regular and module method events to existing HTML elements and also demonstrates the listener-based forms.

    4.3.7 Server-Orchestrated JavaScript Execution

    Method Events demonstrate an important characteristic of WebForms Core. JavaScript remains available as a native browser capability, but the server can orchestrate when a JavaScript method is invoked without requiring the developer to manually write the event registration code in JavaScript.

    The server does not execute the JavaScript method itself. The WebForms class creates the corresponding Action Control, and WebFormsJS interprets that command in the browser and performs the client-side method invocation.

    This keeps the execution model consistent with the broader WebForms Core architecture:

    Method Events are therefore useful when a WebForms Core application needs to combine server-orchestrated UI behavior with existing JavaScript functionality, without requiring the server-side code to implement the JavaScript logic itself.

    4.3.8 Summary

    Method Events provide a bridge between HTML events and client-side JavaScript methods.

    • SetMethodEvent assigns a JavaScript method to an HTML event.
    • SetMethodEventListener provides the listener-based form.
    • SetModuleMethodEvent assigns a method provided through the module system.
    • SetModuleMethodEventListener provides the listener-based module form.
    • All four methods support optional object[] arguments.
    • The corresponding Remove... methods remove the event-method assignments.
    • CallMethod and CallModuleMethod invoke methods directly as Action Controls rather than assigning them to events.

    Method Events allow WebForms Core to use JavaScript as an extension of the Browser Runtime while keeping event orchestration under the control of the WebForms class.