Code-behind model allows for code separation of the pages business logic from its presentation logic
presentation logic for the page is stored in an .aspx page, whereas the logic piece is stored in a separate class file: .aspx.vb or .aspx.cs.
File Options Using Code-Behind File Created
Web Form .aspx file
.aspx.vb or .aspx.cs file
Master Page .master file
.master.vb or .master.cs file
Web User Control .ascx file
.ascx.vb or .ascx.cs file
Web Service .asmx file
.asmx.vb or .asmx.cs file
An .aspx page that uses the ASP.NET 2.0 code-behind model (VB version)
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
Simple Page
A code-behind page (VB version)
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "Hello " & TextBox1.Text
End Sub
End Class
An .aspx page that uses the ASP.NET 2.0 code-behind model (C# version)
<%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="_aspx" %>
Simple Page
A code-behind page (C# version)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Hello " + Textbox1.Text;
}
}