Modular Structure in CodeBehind
Source: Dev.to
What is CodeBehind?
CodeBehind is a powerful backend framework built on years of experience with ASP.NET WebForms from Microsoft. Developed by Elanat, it targets the latest .NET versions (currently .NET 10).
CodeBehind’s Modular Structure
By default, CodeBehind provides a revolutionary modular structure. You can copy and paste an ASPX file together with its compiled DLL from another project into a live web system without rebuilding or republishing the entire project.
This gives developers a vanilla PHP‑like experience in a compiled .NET environment: lightweight, flexible, and fast. Any project built with CodeBehind is inherently modular.
How to Create a New Module
You can copy either an ASPX file (view) or a DLL (controller). The two scenarios are described below.
Example 1: View Only
In WebForms Core, a view can exist without a controller, meaning a single ASPX file can be a module.
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!";
}
## Random Number Generator in CodeBehind
Your random number: **@number**
Message: *@message*
@for (int i = 0; i
An "About Us" page provides information about a company, organization, or individual.
It tells the brand’s story, shares its vision, history, and values, introduces the team,
and builds trust with users.
Step 5 – Add a controller
using CodeBehind;
namespace ModuleProject
{
public partial class AboutController : CodeBehindController
{
public void PageLoad(HttpContext context)
{
ViewData.Add("title", "About page");
}
}
}
Step 6 – Publish the project
Deploy the module by:
- Copying
Default.aspxtowwwroot/aboutin the live project. - Copying the compiled DLL to
wwwroot/bin.
Then trigger recompilation:
SetCodeBehind.CodeBehindCompiler.ReCompile();
Your new module becomes active without rebuilding the main project, demonstrating the true modularity of CodeBehind.
Related links
- CodeBehind on GitHub:
- CodeBehind on NuGet:
- CodeBehind page:
