DEV Community

Cover image for CodeBehind 3.9 Released
elanatframework
elanatframework

Posted on

CodeBehind 3.9 Released

Server-side era

In the past, the term back-end did not exist in web development, and the term server-side was used. One technology whose architecture allowed systems to be developed entirely on the server was Microsoft's earlier Web Forms.

Is WebForms dead?

Almost no organizations and developers are building new applications with Microsoft's old WebForms, they are just extending existing ones.

Why is WebForms obsolete?

WebForms is an old technology, introduced in 2002, and its role in new development has been minimized due to the industry's shift towards more modern and efficient frameworks and the challenges associated with its legacy status. WebForms had many disadvantages for web development and is no longer being developed by Microsoft.

Is WebForms in .NET Core?

Microsoft has not yet added WebForms to .NET Core and it seems that it has no intention of doing so, but Elanat offers a revolutionary technology called WebForms Core that allows you to manage HTML DOMs from the server.

Focusing on the Front-End

In recent years, web development has shifted from back-end to front-end. The development of JavaScript and the existence of powerful frameworks such as React, Angular and Vue made the development focus on the front side.

Focusing on the front-end side has led to minimizing the processing load on the server and reducing bandwidth. However, it has caused a lot of confusion in the development and maintenance of web systems. Lack of flexibility, complex learning and update problems are some of the disadvantages of front-end development.

The Beginning of WebForms Core

The Most Important Web Technology of 2024

In 2024, Elanat ended the problems of web development on both the back-end and front-end sides with the introduction of WebForms Core technology.

WebForms Core introduces a different paradigm, including new logistical advantages. WebForms Core is a revolutionary technology that combines the best of both worlds (back-end and front-end) by providing an automated structure.

WebForms Core is a new feature in the CodeBehind framework that allows you to manage HTML tags from the server.

WebForms Core Advantages

  • Rapid development (server-side development only, no client-side scripting required)
  • Reduced server load (Generation of Action Controls codes in INI format)
  • Less chance of errors (The communication protocol between the server and the client has been tested many times in advance)
  • Maintaining HTML states (works based on AJAX and maintains the state of the page.)

CodeBehind 3.9

Version 3.9 of the CodeBehind framework was introduced with the ability to add events to WebForms Core.

Assign events

In version 3.9 and later of the CodeBehind framework, you will be able to set events on HTML tags. All JavaScript events are supported in WebForms Core technology.
The following page shows a complete list of events in JavaScript:
https://www.w3schools.com/jsref/dom_obj_event.asp

Example

In the following controller class, an instance of the WebForms class is created and the mouse over event on the div tag with ID Div1 results in the response of the random.aspx page on the tag with ID Div2.

Controller

using CodeBehind;

public partial class SetEventController : CodeBehindController
{
    public void PageLoad(HttpContext context)
    {
        WebForms form = new WebForms();
        form.SetGetEvent("Div1", HtmlEvent.OnMouseOver, "Div2", "/random.aspx");

        Write(form.ExportToWebFormsTag());
    }
}
Enter fullscreen mode Exit fullscreen mode

The view consists of two div elements, which when the mouse hovers over Div1, initiates an action that affects Div2.

View

@page
@layout "/layout.aspx"
@controller SetEventController
@{
  ViewData.Add("title","Set event page");
}
<div id="Div1">Set random value to Div2 after mouse over</div>
<div id="Div2">My div 2</div>
Enter fullscreen mode Exit fullscreen mode

TagBack feature

TagBack is a new mechanism in version 3.9 of the CodeBehind framework. TagBack is a new method in WebFormsJS that aims to render Action Controls in the ac attribute of the web-forms tag. Setting the TagBack event allows developers to manipulate server elements without having to revisit the server.

Example

In the controller class below, an instance of the WebForms class is first created. Then, the action of changing the background of the body tag to green is stored in a web-forms tag with the ID MyAC. Next, due to the principles of processing on the server, we clean the created instance of the WebForms class with the Clean method (we could have created a new instance of the WebForms class). By calling the SetTagEvent method, we set the click event on the tag with the ID MYTag equal to the ID of the created web-forms tag (MyAC).

Note: Calling the ExportToWebFormsTag method causes a new instance of the web-forms tag to be created; this tag is rendered in the browser after the HTML page is called. However, the DoneToWebFormsTag method creates an instance of the web-forms tag with the done attribute to prevent it from being executed after the page is executed in the browser.

Controller

using CodeBehind;

public partial class SetTagBackController : CodeBehindController
{
    public void PageLoad(HttpContext context)
    {
        WebForms form = new WebForms();
        form.SetBackgroundColor("<body>", "green");
        Write(form.DoneToWebFormsTag("MyAC"));
        form.Clean();

        form.SetTagEvent("MyTag", HtmlEvent.OnClick, "MyAC");

        Write(form.ExportToWebFormsTag());
    }
}
Enter fullscreen mode Exit fullscreen mode

Clicking on the b tag in the View below will turn the background color green.

View

@page
@layout "/layout.aspx"
@controller SetTagBackController
@{
  ViewData.Add("title","Set tag back page");
}
<b id="MyTag">Click to change background color</b>
Enter fullscreen mode Exit fullscreen mode

Conclusion

The enhancements in CodeBehind version 3.9 provide developers with powerful tools to create dynamic and responsive web applications. By enabling direct event handling through server-side code, it simplifies development and reduces reliance on client-side scripts while maintaining a clean separation between logic and presentation.
The TagBack feature in CodeBehind's WebFormsJS framework significantly simplifies client-server interactions by allowing developers to manipulate server-side components without full postbacks. This results in a more responsive web application experience by reducing unnecessary server calls and enhancing user engagement through dynamic updates.

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)