Code behind (VB.net) : Code behind « ASP.Net Instroduction « ASP.NET Tutorial






<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="FirstPageCodeBehind" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>First Page Code-Behind</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <asp:Button
        id="Button1"
        Text="Click Here"
        Runat="server" />
    
    <br /><br />
        
    <asp:Label
        id="Label1"
        Runat="server" />    
    
    </div>
    </form>
</body>
</html>


File: Default.aspx.vb


Partial Class FirstPageCodeBehind
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label1.Text = "Click the Button"
    End Sub


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = "Thanks!"
    End Sub

End Class








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)