DEV Community

Elanat Framework
Elanat Framework

Posted on

Modular Structure in CodeBehind

What is CodeBehind?

CodeBehind is a powerful backend framework built upon years of experience and research on ASP.NET WebForms from Microsoft. This framework, developed by Elanat, is designed for the latest .NET versions (currently .NET 10).


CodeBehind’s Modular Structure

By default, CodeBehind provides a revolutionary modular structure. In this structure, you can copy and paste an ASPX file along with its compiled DLL from another project into a live web system without needing to rebuild or republish the entire project.

Modular Structure in .NET

This capability gives developers a vanilla PHP–like experience in a compiled .NET environment: lightweight, flexible, and fast. Essentially, any project built with CodeBehind is inherently modular.


How to Create a New Module

As mentioned, you can copy either an ASPX file or a DLL. Here’s how to handle these two scenarios separately.


Example 1: View Only

In WebForms Core, you can have a View without a controller. This means a single ASPX file can itself be a module.

Here’s a simple ASPX view that generates random numbers:

random.aspx

@page
@layout "/layout.aspx"
@{
    // Generate a random number between 1 and 100
    var rnd = new Random();
    int number = rnd.Next(1, 101);

    // Generate a message based on the number
    string message = number > 50 ? "The number is big!" : "The number is small!";
}

<h2>Random Number Generator in CodeBehind</h2>
<p>Your random number: <strong>@number</strong></p>
<p>Message: <em>@message</em></p>

<ul>
@for (int i = 0; i < 5; i++)
{
    <li>Another random number: @rnd.Next(1, 101)</li>
}
</ul>

<p style="color: green;">Here is a list of 5 more random numbers.</p>
Enter fullscreen mode Exit fullscreen mode

Place the View file anywhere in the wwwroot directory (this path is configurable).

⚠️ Note: To add a module (in this case, a View), you need a mechanism to trigger the compilation step:

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

You can, for example, create a View management page where you upload new Views and then call the code above after a successful upload.


Example 2: DLL Module

Steps to create a module project:

Step 1: Create a new empty ASP.NET Core project in Visual Studio Code (targeting .NET 10.0).

Step 2: Install the latest CodeBehind framework via NuGet packages.

Step 3: Configure the Program.cs class:

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

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

Step 4: Create a Default.aspx file under wwwroot/about:

@page
@layout "/layout.aspx"
@controller ModuleProject.AboutController
<p>
    An "About Us" page provides information about a company, organization, or individual. 
    It tells the brands story, shares its vision, history, and values, introduces the team, 
    and builds trust with users.
</p>
Enter fullscreen mode Exit fullscreen mode

Step 5: Add a controller class:

using CodeBehind;

namespace ModuleProject
{
    public partial class AboutController : CodeBehindController
    {
        public void PageLoad(HttpContext context)
        {
            ViewData.Add("title", "About page");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Step 6: Publish the project.


Now, to deploy the module:

  1. Copy the Default.aspx file to wwwroot/about in the live project.
  2. Copy the compiled DLL from the module project into wwwroot/bin.
  3. Trigger the compilation mechanism:
SetCodeBehind.CodeBehindCompiler.ReCompile();
Enter fullscreen mode Exit fullscreen mode

After this, your new module is fully active and integrated into the live system without rebuilding the main project.


This structure demonstrates the true modularity of CodeBehind: independent Views and DLLs can be added dynamically, making development fast, flexible, and very close to a “vanilla PHP” experience in a fully compiled .NET environment.

Related links

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

CodeBehind in NuGet:
https://www.nuget.org/packages/CodeBehind/

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

Top comments (0)