code-behind model allows for code separation of the page's business logic from its presentation logic : Code behind « ASP.Net Instroduction « ASP.NET Tutorial

ASP.NET Tutorial
1. ASP.Net Instroduction
2. Language Basics
3. ASP.net Controls
4. HTML Controls
5. Page Lifecycle
6. Response
7. Collections
8. Validation
9. Development
10. File Directory
11. Sessions
12. Cookie
13. Cache
14. Custom Controls
15. Profile
16. Configuration
17. LINQ
18. ADO.net Database
19. Data Binding
20. Ajax
21. Authentication Authorization
22. I18N
23. Mobile
24. WebPart
25. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.NET Tutorial » ASP.Net Instroduction » Code behind 
1. 3. 2. code-behind model allows for code separation of the page's 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" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
   <title>Simple Page</title>
</head>
<body>
   <form runat="server">
      What is your name?<br />
      <asp:Textbox ID="Textbox1" Runat="server"></asp:Textbox><br />
      <asp:Button ID="Button1" Runat="server" Text="Submit"
       OnClick="Button1_Click" />
      <asp:Label ID="Label1" Runat="server"></asp:Label>
   </form>
</body>
</html>

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.EventArgsHandles 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" %>
 
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
   <title>Simple Page</title>
</head>
<body>
   <form runat="server">
      What is your name?<br />
      <asp:Textbox ID="Textbox1" Runat="server"></asp:Textbox><br />
      <asp:Button ID="Button1" Runat="server" Text="Submit"
       OnClick="Button1_Click" />
      <asp:Label ID="Label1" Runat="server"></asp:Label>
   </form>
</body>
</html>


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;
   }
}
1. 3. Code behind
1. 3. 1. code-inline model: all the code is contained within a single .aspx page
1. 3. 2. code-behind model allows for code separation of the page's business logic from its presentation logic
1. 3. 3. Use Code behind
1. 3. 4. Code behind (VB.net)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.