DEV Community

Cover image for CodeBehind 4.8 Released
Elanat Framework
Elanat Framework

Posted on

CodeBehind 4.8 Released

CodeBehind

CodeBehind is a server-side web framework for .NET that enables developers to build dynamic web applications using C# and standard web technologies. It provides a structured approach to server-side page development while supporting modern web application architectures.

What's New in CodeBehind 4.8

CodeBehind 4.8 includes WebForms Core 2.2, bringing the latest WebForms Core features and improvements to CodeBehind applications.

In WebForms Core 2.2, Render, Snapshot, and Rollback are new structural rendering primitives.

Snapshot captures the current HTML structure of a target element and stores it as a stable rendering base under a specified key. Rollback restores the target to a previously captured snapshot before further commands are applied, preventing repeated renders from accumulating stale attributes or values.

Render is a higher-level rendering operation built on these two primitives and TransientDom. It checks whether a rendering base already exists, restores it with Rollback or creates it with Snapshot, then opens an isolated transient DOM scope on a clone of the target. The supplied WebForms commands are applied within that scope, after which the modified clone replaces the original target in a single DOM operation.

This allows repeated renders to start from a known structural state while remaining isolated, predictable, and repeatable, without using a virtual DOM.

We will introduce the new features of WebForms Core 2.2 in detail in a separate article soon.

From this version onward, the minified version of WebFormsJS is included in the CodeBehind framework.

The web-forms.min.js file is also added to the initial CodeBehind template by default.

The Control Method Has Been Removed

The Control method has been completely removed.

The web_forms_view_place option has also been removed.

The use_comment_mode_for_web_forms_combinate option has also been removed.

The options structure has been redesigned to provide more reliable behavior when options are removed or renamed.

After a successful update, an outdate section will be added to the end of the options file after a blank line. This section is no longer associated with the active options and has no effect on CodeBehind functionality.

For example:

;outdate
web_forms_view_place=<body>
use_comment_mode_for_web_forms_combinate=false
Enter fullscreen mode Exit fullscreen mode

Going forward, use Write(form.ExportToHtmlComment()) instead of Control(form) when sending WebForms commands that include HTML.

For secondary commands that do not include HTML, use Write(form.Response()) together with IgnoreAll(). The IgnoreAll() method prevents the view and layout from being rendered.

Why Was the Control Method Removed?

There were two main reasons:

  1. Performance improvement: Although the overhead was minimal, the Control method introduced additional processing on every request. Removing it eliminates this unnecessary overhead and improves the overall performance of the CodeBehind framework.

  2. Standardization of the WebForms class: The WebForms class is available across a wide range of programming languages. The Control method introduced a language-specific syntactical pattern that was inconsistent with the design of the WebForms class across different implementations. Removing it provides a more consistent and standardized API across languages.

How to Update CodeBehind on Active Systems

To update to the new version, first replace the existing CodeBehind.dll with the latest version. Also replace or add your application's DLL, ASPX, and other required files as needed.

Then, it is recommended to systematically execute the following method from one of your admin paths:

SetCodeBehind.CodeBehindCompiler.ReCompile();
Enter fullscreen mode Exit fullscreen mode

If you cannot execute this method systematically for any reason, delete the following files from your web server or hosting environment:

CodeBehindLastSuccessCompiled.dll.tmp
code_behind/views_class.cs.tmp
Enter fullscreen mode Exit fullscreen mode

Then disable and re-enable your system on the web server or hosting environment.

Development Configuration

When developing a CodeBehind application on your local system, it is recommended to use the following configuration:

builder.Services.AddCodeBehind(!builder.Environment.IsDevelopment());
Enter fullscreen mode Exit fullscreen mode

This configuration automatically determines whether the application is running in development mode or in its final production environment on the web server.

Installation and Requirements

CodeBehind is available as a NuGet package for ASP.NET Core applications.

Install CodeBehind using the .NET CLI:

dotnet add package CodeBehind
Enter fullscreen mode Exit fullscreen mode

Or add it directly to the project file:

<PackageReference Include="CodeBehind" />
Enter fullscreen mode Exit fullscreen mode

CodeBehind requires ASP.NET Core and a supported version of .NET (Version 10). For the exact supported target frameworks and package requirements, see the CodeBehind Package on NuGet.

After installing the package, configure CodeBehind in Program.cs:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddCodeBehind(!builder.Environment.IsDevelopment());

var app = builder.Build();

app.UseCodeBehind();    // UseCodeBehindAsync() for asynchronous execution
                        // UseCodeBehindNextNotFound() to continue if the page is not found

app.Run();
Enter fullscreen mode Exit fullscreen mode

Related Links

Elanat:

GitHub:

NuGet:

Top comments (0)