code-inline model: all the code is contained within a single .aspx page : Code behind « ASP.Net Instroduction « ASP.NET Tutorial






File Options Using Inline Coding          File Created
Web Form                                  .aspx file 
Master Page                               .master file 
Web User Control                          .ascx file 
Web Service                               .asmx file 


 
File: Default.aspx (VB)
<%@ Page Language="VB" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    
<script runat="server">
   Protected Sub Button1_Click(ByVal sender As Object, _
      ByVal e As System.EventArgs)
    
      Label1.Text = "Hello " & Textbox1.Text
   End Sub
</script>
    
<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>


File: Default.aspx (C#)
<%@ Page Language="C#" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    
<script runat="server">
   protected void Button1_Click(object sender, System.EventArgs e)
   {
      Label1.Text = "Hello " + Textbox1.Text;
   }
</script>

    
<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>








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)