DEV Community

Cover image for Similarities of the CodeBehind Framework with the Microsoft WebForms
elanatframework
elanatframework

Posted on

Similarities of the CodeBehind Framework with the Microsoft WebForms

In 2023, a Back-End framework based on .NET version 7 called CodeBehind was created by Elanat. About a year later, Elanat created a revolutionary technology called WebForms Core and added it to the core of the CodeBehind framework. Now the CodeBehind framework is a Full-Stack framework that manages both the Back-End and the Front-End together.

When the CodeBehind framework was introduced, it was clear that the structure and some of the naming conventions in the CodeBehind framework were similar to the old Microsoft WebForms. The ability to manage HTML tags from the server in the WebForms Core technology further enhanced this similarity.

Elanat WebForms Core Example
WebForms Core

Microsoft WebForms Example
WebForms

The following table compares the WebForms Core technology with the former Microsoft WebForms.

WebForms in .NET Core

In this article, we want to highlight the similarities between the two frameworks.

Note: Please note that the CodeBehind framework is a modern, high-level framework, and its similarity to the old Microsoft WebForms is only nostalgic.

WebForms VS MVC

ASPX Extension

View Pages: ASPX is a file extension that stands for Active Server Pages Extended. ASPX files are web pages that are rendered and then compiled by .NET. The CodeBehind framework, like Microsoft's former WebForms, uses these pages for the View section.

PageLoad Method

Execution Method: PageLoad is a method in the CodeBehind framework Controller that is used to initialize page content, set up data bindings, or perform any other task that needs to be performed after the page is requested. The PageLoad method is invoked when a page is requested in which the specified Controller is specified. The PageLoad method is similar to the Page_Load method in the former Microsoft WebForms CodeBehind section (not to be confused with the CodeBehind framework name!).

Compile

Recompiling Pages: When ASPX pages are compiled in the old WebForms, the entire session is cleared and active users are denied access; however, in the CodeBehind framework, ASPX pages are rendered in a final View class and only that class is compiled; so the session is not lost.

Standard Syntax

Embedding Dynamic Content: Early versions of the CodeBehind framework supported a syntax similar to the old WebForms. Since version 1.8, the CodeBehind framework also supports Razor syntax. Microsoft calls this syntax "Inline Expression Syntax". However, Elanat uses the name "Standard syntax" for this syntax.

Controller VS (CodeBehind or Inherits)

Attributes in Directive Section: The code below is the page directive section in the old Microsoft WebForms.

<%@ Page Language="C#" CodeBehind="user-form.aspx.cs" Inherits="asp.netexample.user_form" %>  
Enter fullscreen mode Exit fullscreen mode

In the old WebForms, the two attributes CodeBehind and Inherits provide similar functionality to Controller in the CodeBehind framework. The Codebehind attribute defines the name of the file containing the code-behind code. The Inherits attribute defines the class in the code-behind file that inherits from System.

Automatic routing

Routing Mechanism: Both frameworks utilize automatic routing based on the .aspx file path, simplifying navigation within applications. This feature allows developers to define routes without extensive configuration, reminiscent of the routing simplicity found in WebForms

Separation of Concerns

Separation of Code and Design: Just like WebForms, CodeBehind maintains a clear separation between server-side logic and HTML design. This means that developers do not need to mix server-side code within their view files, promoting cleaner code organization. However, the CodeBehind framework uses a high-level architecture that allows you to use WebForms Core technology in the MVC pattern.

Event-Driven Programming Model

Event Handling: The CodeBehind framework retains the event-driven programming model characteristic of WebForms, allowing developers to handle events on the server side while managing HTML elements directly from the server. This is reminiscent of how controls in WebForms were managed through event handlers. In the CodeBehind framework, event control is simple and all HTML and JavaScript events are supported.

Server-Side Control Management

Control Management: CodeBehind Framework introduces a new technology called WebForms Core that facilitates server-side management of HTML tags, echoing the control management features found in traditional WebForms. This allows developers to manipulate page elements dynamically from the server. In WebForms Core technology, there is no need to specify runat=server and <asp: and all HTML tags are controlled on the server side without additional attributes and prefixes.

Conclusion

While CodeBehind is a modern framework that incorporates advanced features and performance improvements over legacy systems, its similarities with Microsoft WebForms evoke nostalgia for developers familiar with earlier technologies. The combination of familiar structures and innovative enhancements positions CodeBehind as a compelling choice for modern web development within the .NET ecosystem.

Related links

CodeBehind on GitHub:
https://github.com/elanatframework/Code_behind

Get CodeBehind from NuGet:
https://www.nuget.org/packages/CodeBehind/

CodeBehind page:
https://elanat.net/page_content/code_behind

Top comments (0)