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.
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Asp.Net Code Behind Model Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<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" />
</div>
</form>
</body>
</html>
Default.aspx.cs
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: " +
TextBox1.Text.ToString();
}
}
- AccessKey example: how to use AccessKey in asp.net
- Asp.Net Inline Coding Model Example
- BulletedList control example
- Panel example: how to use Panel control in asp.net
- TextBox example: how to use TextBox control in asp.net
- TextBox example: how to use TextMode property Password
- TextBox example: how to use TextMode property MultiLine
- TextBox example: using OnTextChanged event with AutoPostBack
- Literal example: how to use Mode Encode, PassThrough, Transform