ASP.NET Architecture, Part 2
(Page 1 of 7 )
In this second of a two-part series, Dwight takes us through the new ASP.NET Architecture. We learn about ASP.NET's System.Web.UI namespace classes, interfaces, enumerations, and delegates. We also learn about the ASP.NET page class, including a close look at the life cycle of an ASP.NET page, applying page directives, and the code-behind feature. This piece comes from chapter six of February's Developer Shed Writing Contest prize,
.NET & J2EE Interoperability, by Dwight Peltzer (McGraw-Hill/Osborne, ISBN 0-07-223-054-1, 2004).
Defining Web Form Functionality
Let’s create a new project in Visual Studio .Net. Begin by creating a virtual directory called MyASP.NETPages. Then open Visual Studio .NET and create the new ASP.NET web application project called IFCE. Initially, the location where the application will be stored looks like this: http://localhost/WebApplication1. Rename it to the correct project name, “IFCE.” Also, rename public class1 to Register. Notice how public class Register inherits from class System.Web.UI.Page. The next item of interest, Private Sub InitializeComponent(), calls the subroutine InitializeComponent(). Next, Private Sub Page_Init(ByVal sender as System.Object, ByVal e as System.EventArgs) Handles MyBase.Init initializes the page.
Public
Class Register
Inherits System.Web.UI.Page
#Region "Web Form Designer Generated Code"
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration
is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent ()
End Sub
#End Region
End Class
WebForm1.aspx displays the code-behind feature. Inside the ASP.NET script delimiters, the page language is VB; the CodeBehind is Web Form1.aspx.vb. The code indicates that the web form inherits from the IFCE WebForm1. The form ID is Form1; the method is Post, specifying that the page must run on the server.
%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="IFCE.WebForm1"%>
<html>
<head>
<TITLE>WebForm1</TITLE>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE LANGUAGE" content = "Visual Basic .NET 7.1">
<meta name="defaultClientScript content="JavaScript">
<meta name="vc_targetSchema content="http://schemas.Microsoft.com/
intellisense/ie5">
</head>
</html>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server>
</form>
</body>
</html>
Next, click on the Register icon in the Solution Explorer and select View Designer. Then, click on the Toolbox icon and drag a label onto the web form. Select the label’s properties and type RegisterClient to the right of the text property. Finally, compile the application, and the label will display in Internet Explorer as follows:
Register Client
This has been part two of ASP.NET Architecture (see part 1 here), chapter six of .NET & J2EE Interoperability, by Dwight Peltzer (McGraw-Hill/Osborne, ISBN 0-07-223054-1, 2004).
Buy this book now. |
Next: The Global.aspx.vb File >>
More ASP.NET Articles
More By McGraw-Hill/Osborne