• 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.1 HTTP Events

    4.1 HTTP Events

    WebForms Core provides HTTP event methods for connecting browser events directly to server requests. These methods allow a developer to define what HTTP request should be sent when an HTML event or an event listener is triggered, without manually writing fetch(), XMLHttpRequest code, request headers, serialization logic, or response-handling code.

    HTTP events are defined through the WebForms class and are executed by WebFormsJS in the browser. The server therefore defines the behavior, while WebFormsJS creates and manages the corresponding browser-side request.

    The HTTP event methods support GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD, and the more general Send request mechanism.

    4.1.1 HTTP Event Structure

    Most HTTP event methods are available in two forms:

    • Event: uses an HTML event such as onclick, onchange, or onsubmit.
    • EventListener: uses the WebFormsJS event-listener mechanism and accepts an event such as click, keyup, or another supported listener event.

    For the HTTP methods that support an OutputPlace, the response can be directed to a specific location in the DOM.

    4.1.2 Response Handling

    HTTP event responses can contain either HTML output or WebForms Core Action Controls.

    If the server response is not an Action Control response and an OutputPlace has been specified, the returned output is placed in that location. If no OutputPlace is specified, the returned output replaces the previous value of the location defined by WebFormsOptions.ResponseLocation.

    The default value of WebFormsOptions.ResponseLocation is <body>. For applications using a page-level content container, using <main> as the response location is recommended.

    If the server response contains WebForms Core Action Controls, the Action Controls are executed instead of being inserted as ordinary HTML output.

    Note: An HTTP response can therefore be either a UI response or an instruction response. HTML is inserted into the appropriate location, while Action Controls are executed by WebFormsJS.

    4.1.3 GET Events

    The SetGetEvent methods associate an HTML event with an HTTP GET request.

    SetGetEvent

    The basic form is:

    The first argument is the InputPlace. The second argument specifies the HTML event. The optional path specifies the URL requested by the browser.

    Method Description
    SetGetEvent(string InputPlace, string HtmlEvent, string Path = null) Creates a GET request for an HTML event.
    SetGetEvent(string InputPlace, string HtmlEvent, string OutputPlace, string Path = null) Creates a GET request and places a non-Action-Control response in the specified output location.

    If the path is omitted, the default path value is #.

    SetGetEventListener

    The listener version uses an HTML event listener:

    Method Description
    SetGetEventListener(string InputPlace, string HtmlEventListener, string Path = null) Creates a GET request for an event listener.
    SetGetEventListener(string InputPlace, string HtmlEventListener, string OutputPlace, string Path = null) Creates a GET request and places a non-Action-Control response in the specified output location.

    4.1.4 PUT Events

    The SetPutEvent methods associate an event with an HTTP PUT request.

    Method Description
    SetPutEvent(string InputPlace, string HtmlEvent, string Path = null) Creates a PUT request for an HTML event.
    SetPutEvent(string InputPlace, string HtmlEvent, string OutputPlace, string Path = null) Creates a PUT request with a specified output location.
    SetPutEventListener(string InputPlace, string HtmlEventListener, string Path = null) Creates a PUT request for an event listener.
    SetPutEventListener(string InputPlace, string HtmlEventListener, string OutputPlace, string Path = null) Creates a PUT request for an event listener with a specified output location.

    4.1.5 PATCH Events

    The SetPatchEvent methods create HTTP PATCH requests.

    Method Description
    SetPatchEvent(string InputPlace, string HtmlEvent, string Path = null) Creates a PATCH request for an HTML event.
    SetPatchEvent(string InputPlace, string HtmlEvent, string OutputPlace, string Path = null) Creates a PATCH request with a specified output location.
    SetPatchEventListener(string InputPlace, string HtmlEventListener, string Path = null) Creates a PATCH request for an event listener.
    SetPatchEventListener(string InputPlace, string HtmlEventListener, string OutputPlace, string Path = null) Creates a PATCH request for an event listener with a specified output location.

    4.1.6 DELETE Events

    The SetDeleteEvent methods create HTTP DELETE requests.

    Method Description
    SetDeleteEvent(string InputPlace, string HtmlEvent, string Path = null) Creates a DELETE request for an HTML event.
    SetDeleteEvent(string InputPlace, string HtmlEvent, string OutputPlace, string Path = null) Creates a DELETE request with a specified output location.
    SetDeleteEventListener(string InputPlace, string HtmlEventListener, string Path = null) Creates a DELETE request for an event listener.
    SetDeleteEventListener(string InputPlace, string HtmlEventListener, string OutputPlace, string Path = null) Creates a DELETE request for an event listener with a specified output location.

    4.1.7 OPTIONS Events

    The SetOptionsEvent methods create HTTP OPTIONS requests.

    Method Description
    SetOptionsEvent(string InputPlace, string HtmlEvent, string Path = null) Creates an OPTIONS request for an HTML event.
    SetOptionsEvent(string InputPlace, string HtmlEvent, string OutputPlace, string Path = null) Creates an OPTIONS request with a specified output location.
    SetOptionsEventListener(string InputPlace, string HtmlEventListener, string Path = null) Creates an OPTIONS request for an event listener.
    SetOptionsEventListener(string InputPlace, string HtmlEventListener, string OutputPlace, string Path = null) Creates an OPTIONS request for an event listener with a specified output location.

    4.1.8 HEAD Events

    The SetHeadEvent methods create HTTP HEAD requests.

    HEAD events are different from the other HTTP event methods in that the WebForms methods do not provide an OutputPlace parameter. The SetHeadEvent and SetHeadEventListener methods only define the request path and event.

    Method Description
    SetHeadEvent(string InputPlace, string HtmlEvent, string Path = null) Creates a HEAD request for an HTML event.
    SetHeadEventListener(string InputPlace, string HtmlEventListener, string Path = null) Creates a HEAD request for an event listener.
    Note: The server-side SetHead method does not return a value. It is therefore not an output-producing method.

    4.1.9 POST Events

    POST events have a special relationship with HTML forms. All six SetPostEvent methods operate only on tags that are inside a <form> element. They do not operate on elements outside a form.

    When a POST event is required outside a form, other HTTP event methods such as PUT can be used. The general Send event is another option when the request requires explicit control over the request data, method, content type, or output location.

    SetPostEvent

    The basic POST event associates an HTML event with the form submission request:

    The form data is submitted using the POST method.

    The six POST event methods are:

    Method Description
    SetPostEvent(string InputPlace, string HtmlEvent) Creates a POST event for an element inside a form.
    SetPostEvent(string InputPlace, string HtmlEvent, string OutputPlace) Creates a POST event and specifies where a non-Action-Control response is placed.
    SetPostEventAddView(string InputPlace, string HtmlEvent) Creates a POST event that adds HTML output as a new view.
    SetPostEventListener(string InputPlace, string HtmlEventListener) Creates a POST event listener for an element inside a form.
    SetPostEventListener(string InputPlace, string HtmlEventListener, string OutputPlace) Creates a POST event listener with a specified output location.
    SetPostEventListenerAddView(string InputPlace, string HtmlEventListener) Creates a POST event listener that adds HTML output as a new view.

    POST Output Location

    When an OutputPlace is supplied, a normal HTML response is placed at that location.

    For example, if the server returns HTML, WebFormsJS places that output in the element represented by Result. If the response is an Action Control response, the Action Controls are executed instead.

    POST Add View

    SetPostEventAddView and SetPostEventListenerAddView provide a special output mode for HTML responses.

    If the response contains HTML, the returned content is added to the beginning of the element configured as WebFormsOptions.ResponseLocation. The default value is <body>.

    For applications that use a dedicated page content area, it is recommended to configure WebFormsOptions.ResponseLocation as <main>.

    This allows a POST request to return a new view that is inserted at the beginning of the application's main content area.

    4.1.10 Send Events

    The SetSendEvent methods provide a general HTTP request mechanism. Unlike the specialized GET, PUT, PATCH, DELETE, OPTIONS, HEAD, and POST event methods, Send allows the developer to specify the request data, URL, HTTP method, multipart mode, content type, and output location.

    This makes Send suitable when the request does not fit the specialized event methods or when the developer needs explicit control over the request payload.

    SetSendEvent

    The method signature is:

    Parameter Description
    InputPlace The element on which the event is assigned.
    HtmlEvent The HTML event that triggers the request.
    Data The data sent with the request.
    Path The request URL. The default is #.
    Method The HTTP method. The default is POST.
    IsMultiPart Determines whether the data is sent as multipart form data.
    ContentType Specifies the request content type. The default is text/plain.
    OutputPlace Specifies where a normal response is placed.

    For example, the following event sends data using PUT with a plain-text content type:

    The request data can also be obtained dynamically from the DOM through Fetch expressions.

    SetSendEventListener

    The listener version provides the same request capabilities while using an HTML event listener:

    Its signature is:

    4.1.11 Using Send for POST Requests Outside a Form

    Because the specialized POST event methods operate only on elements inside a <form>, SetSendEvent can be used when a POST request must be triggered by an element outside a form.

    This approach also provides explicit control over the request data and content type.

    4.1.12 Using Send with Other HTTP Methods

    Send can use HTTP methods beyond POST. For example, the same mechanism can be used for PUT or DELETE requests:

    This makes Send a general-purpose HTTP event method rather than a method restricted to a particular HTTP verb.

    4.1.13 Multipart Requests

    The IsMultiPart parameter controls whether the data is sent according to the form as multipart data. The source implementation specifically documents this mode as sending the data based on the form with the content key.

    The same option is available in SetSendEventListener.

    4.1.14 Complete HTTP Event Example

    The following example demonstrates the main HTTP event types together. Each request is associated with a different HTML event, and responses that are ordinary HTML can be directed to a specific output location.

    4.1.15 HTTP Event Selection

    Method HTTP Request OutputPlace Event EventListener
    SetGetEvent GET Yes Yes Yes
    SetPutEvent PUT Yes Yes Yes
    SetPatchEvent PATCH Yes Yes Yes
    SetDeleteEvent DELETE Yes Yes Yes
    SetOptionsEvent OPTIONS Yes Yes Yes
    SetHeadEvent HEAD No Yes Yes
    SetPostEvent POST Specialized Yes Yes
    SetSendEvent Configurable Yes Yes Yes

    4.1.16 Removing HTTP Events

    WebForms Core provides a corresponding Remove method for HTTP events. These methods remove a previously assigned HTTP event or HTTP event listener from the specified element.

    Each HTTP request type has two removal methods: one for HTML events and one for event listeners.

    Removing GET Events

    RemoveGetEvent removes a GET event assigned through SetGetEvent, while RemoveGetEventListener removes a GET event listener assigned through SetGetEventListener.

    Removing PUT Events

    These methods remove PUT event and PUT event listener assignments respectively.

    Removing PATCH Events

    These methods remove PATCH event and PATCH event listener assignments respectively.

    Removing DELETE Events

    These methods remove DELETE event and DELETE event listener assignments respectively.

    Removing OPTIONS Events

    These methods remove OPTIONS event and OPTIONS event listener assignments respectively.

    Removing HEAD Events

    These methods remove HEAD event and HEAD event listener assignments respectively.

    Removing POST Events

    The POST removal methods follow the same event and event listener distinction. Since POST events are assigned only to elements inside a <form>, their removal methods operate on those POST event assignments.

    The removal method does not require an OutputPlace. The event assignment itself is identified by the input place and event type.

    Removing Send Events

    The general Send event mechanism also provides separate removal methods for HTML events and event listeners.

    These methods remove the corresponding SetSendEvent and SetSendEventListener assignments.

    HTTP Event Removal Methods

    HTTP Type HTML Event Event Listener
    GET RemoveGetEvent RemoveGetEventListener
    POST RemovePostEvent RemovePostEventListener
    PUT RemovePutEvent RemovePutEventListener
    PATCH RemovePatchEvent RemovePatchEventListener
    DELETE RemoveDeleteEvent RemoveDeleteEventListener
    OPTIONS RemoveOptionsEvent RemoveOptionsEventListener
    HEAD RemoveHeadEvent RemoveHeadEventListener
    Send RemoveSendEvent RemoveSendEventListener

    The removal methods are useful when an HTTP event must be dynamically replaced, disabled, or reconfigured during Action Control execution. The removal operation itself is represented as an Action Control and is therefore executed by WebFormsJS in the browser.

    4.1.17 Summary

    HTTP Events provide a direct bridge between browser events and server-side HTTP operations. Instead of manually implementing browser request code, the developer defines the desired HTTP behavior through the WebForms class.

    The specialized HTTP event methods provide a concise API for common HTTP verbs, while SetSendEvent and SetSendEventListener provide a more configurable request mechanism.

    The resulting architecture keeps the request definition on the server while WebFormsJS performs the browser-side event handling, HTTP communication, and response processing. As a result, an HTTP event can return ordinary HTML for DOM insertion or WebForms Core Action Controls for direct execution in the browser.