ASP.NET Code Behind Model Example

ASP.NET Code Behind Model Example
In Code Behind model of ASP.NET the business logic place a separate file. For this example we need to create two files, one web form name Default.aspx and another file name Default.aspx.cs.

The Default.aspx holds two Label control, one TextBox control and one Button control. The all business logic need to place in Default.aspx.cs file. Here is the source code of both files.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="">
<head runat="server">
    <title>Asp.Net Code Behind Model Example</title>
    <form id="form1" runat="server">
        <asp:Label ID="Label1" runat="server" Font-Size="Large"></asp:Label>
        <br />
        <asp:Label ID="Label2" runat="server" Text="Zip Code" AssociatedControlID="TextBox1"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
    protected void Button1_Click(object sender, System.EventArgs e) {
        Label1.Text = "Your Zip Code: " +
More examples