Presentation tier scripts -------------------------------------------------- web.config -------------------------------------------------- -------------------------------------------------- Imports statements -------------------------------------------------- Imports System.Configuration.ConfigurationManager Imports System.Data Imports System.Data.SqlClient -------------------------------------------------- Region Directives for code-behind -------------------------------------------------- 'Copy these Region Directives into each new Aspx.Net page #Region " Public objects " Public ConnectionString As String = "database=" & AppSettings("DatabaseName") _ & ";server=" & AppSettings("ServerName") & ";User ID=" & AppSettings("UserID") & ";pwd=" & AppSettings("Pwd") 'Set a default for the sortstring column 'Public SortStringColumn As String = "SomeName" #End Region #Region " Click event handlers for page controls " #End Region #Region " Click event handlers for grid views " #End Region #Region " Local subs " Private Sub setFormMode() 'Retrieve the user's profile from session memory 'Dim dtPersonProfile As DataTable = CType(Session("dtPersonProfile"), DataTable) 'If ther user's profile has expired or has not been created (say page was accessed via a bookmark 'favorites, or simply typing the URL), redirect to login 'If dtPersonProfile Is Nothing Then ' Response.Redirect("SignIn.aspx") 'End If End Sub #End Region #Region " Local functions " #End Region #Region " Local utilities " #End Region -------------------------------------------------- Page_Load event PostBack handler -------------------------------------------------- If Not IsPostBack Then SetFormMode() End If -------------------------------------------------- DataSource/DataBind method with Error handling blocks -------------------------------------------------- ''Instantiate an instance of the dataAccess tier (or BusinessLogic tier) 'Dim objDataAccess As New DataAccess.daUser 'Dim objBusinessLogic As New BusinessLogic.blUser ''Providing a test value for Parameter1 'Dim Parameter1 As Integer = 3 ''Create a local data structure 'Dim dtMyLocalTable As DataTable = objDataAccess.GetSomeResult(Parameter1, ConnectionString) 'Dim dtMyLocalTable As DataTable = objBusinessLogic.GetSomeResult(Parameter1, ConnectionString) ''Set DataSource for page control ''Me.PageControl.DataSource = dtMyLocalTable 'If objDataAccess.TransactionSuccessful Then ' 'If a listbox or dropdown list: 'Me.PageControl.DataTextField = "attribute1" 'Me.PageControl.DataValueField = "attribute2" 'Try ' Me.PageControl.DataBind() 'Catch bindError As Exception ' Me.lblSystemMessage.Text = "Control bind error: " & bindError.Message 'End Try ' Else 'Me.lblSystemMessage.Text = "Data tier error: " & objDataAccess.ErrorMessage ' End If -------------------------------------------------- Code snippets for html