In ASP.NET, there isn't a direct equivalent to C/C++'s #include
directive. Instead, ASP.NET uses a concept called "code-behind files" for server-side code separation and organization.
In ASP.NET, code-behind files are separate files that contain the C# or VB.NET code for handling the logic of your web pages. These files have a .cs
extension for C# or a .vb
extension for VB.NET.
Let's say you have an ASP.NET web page named Default.aspx
with some HTML content and you want to handle a button click event. You would create a code-behind file named Default.aspx.cs
(for C#) or Default.aspx.vb
(for VB.NET).
Here's a simple example:
Default.aspx:
Example
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="YourNamespace.Default" %>
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<meta charset="utf-8" />
<title>ASP.NET Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnSubmit" runat="server" Text="Click Me" OnClick="btnSubmit_Click" />
</div>
</form>
</body>
</html>
Example
using System;
using System.Web.UI;
namespace YourNamespace
{
public partial class Default : Page
{
protected void btnSubmit_Click(object sender, EventArgs e)
{
// Handle button click event
Response.Write("Button clicked!");
}
}
}
In this example:
Default.aspx
contains the HTML markup for your web page.CodeBehind
attribute in the <%@ Page %>
directive specifies the code-behind file (Default.aspx.cs
) for this page.Default.aspx.cs
contains the C# code to handle the button click event.When the button is clicked, the btnSubmit_Click
method in Default.aspx.cs
is executed.
So, instead of using #include
to include code files, ASP.NET uses this separation of concerns approach with code-behind files for managing server-side logic.