Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

ASP.NET Classes #include:


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.

Code-Behind Files:

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.

Example:

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>

Default.aspx.cs:

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:

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.


Advertisement
Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java