The WebForms class is the server-side programming interface of WebForms Core. It is the main point of interaction between backend code and the WebForms Core execution model. Developers use this class to describe UI operations, configure browser events, manage client-side behavior, and coordinate communication between the server and the browser.

Unlike traditional server-side rendering approaches, the WebForms class does not generate an HTML document or maintain a server-side representation of the browser DOM. Instead, it produces a sequence of instructions that describe what should happen in the browser. These instructions are then interpreted and executed by WebFormsJS, the client-side execution engine of WebForms Core.

This design establishes a clear separation of responsibilities:

  • WebForms (Server): Defines operations and generates WebForms Core commands.
  • WebFormsJS (Client): Receives and executes those commands against the browser DOM and available browser APIs.

From Server-Side Code to Browser Execution

When a developer calls a method on a WebForms instance, the method does not directly manipulate an HTML element. It adds a corresponding instruction to an internal command buffer. The class stores these instructions in a StringBuilder and combines them into a structured representation of the requested operations.

For example:

WebForms webForms = new WebForms(); webForms.SetText("message", "Welcome!"); webForms.SetVisible("panel", true); webForms.AddClass("panel", "active"); 

These calls describe three operations: changing an element's text, making another element visible, and adding a CSS class. The operations are accumulated on the server rather than being executed there.

Once the instructions are ready, the application can retrieve them through the Response() method:

string response = webForms.Response(); 

The result contains the WebForms Core response marker, [web-forms], followed by the generated instructions. WebFormsJS recognizes this format and processes the commands in the browser.

The class also provides other output methods for different integration scenarios. For example, ExportToHtmlComment() packages the instructions inside an HTML comment, while ExportToLineBreak() produces a line-break-based representation intended for communication scenarios such as Server-Sent Events.

A Command-Oriented Programming Interface

The WebForms class is not limited to basic DOM manipulation. Its API covers a broad range of browser and application operations, including:

  • Adding, modifying, inserting, and removing HTML content and attributes.
  • Managing browser events and event listeners.
  • Configuring HTTP requests and handling different request methods.
  • Working with WebSocket and Server-Sent Events connections.
  • Accessing browser capabilities such as the DOM, Window, Navigator, Screen, and Clipboard APIs.
  • Managing client-side state, storage, cookies, and cached values.
  • Defining conditions, loops, asynchronous operations, and execution sequences.
  • Rendering HTML from templates and working with dynamic variables.
  • Managing components, transient DOM operations, snapshots, and rollback.
  • Integrating JavaScript modules and WebAssembly.

This range of capabilities makes the class more than a collection of DOM helper methods. It provides a server-side interface for describing a broad range of client-side behavior through a unified command model.

Another important aspect is that the class does not require developers to write custom JavaScript for every interaction. Many common browser operations and interaction patterns can be expressed directly through its methods. At the same time, WebForms Core does not prevent developers from using their own JavaScript or integrating existing JavaScript libraries.

Understanding the API Structure

The methods of the WebForms class are organized into logical groups. Some groups provide similar operations with different behaviors. For example, Add, Set, Insert, and Delete handle different ways of changing HTML elements and their properties. Other groups focus on events, browser APIs, communication, state management, rendering, and execution flow.

The class also includes helper types and static methods that support these operations. For example, HtmlEvent and HtmlEventListener provide event-name constants, while WasmLanguage identifies supported WebAssembly language options. The Fetch expression methods provide a way to reference values and information available in the browser.

In the following sections, these groups are examined individually, with an emphasis on their purpose, practical usage, and the technical mechanisms that make them work within WebForms Core.