Professional Documents
Culture Documents
NET
Some references:
Beginning ASP.NET using VB.NET; Wrox; 2002 chpt 2. Kalata, K, Introduction to ASP.NET 2002, chpt 1. Esposito, D. Programming Microsoft ASP.NET, chpt 1. Morrison, M. and Morrison, J. Database driven web sites (2nd edn). Chpt 6. VS.NET on line documentation + Quickstart tutorials
What is .NET?
A Microsoft strategy and new technology for delivering software services to the desktop and to the web Components include:
MS Intermediate Language; all code is complied into a more abstract,
trimmed version before execution. All .NET languages are compiled to MSIL the common language of .NET The CLR- common language runtime; responsible for executing MSIL code; interfaces to Windows and IIS A rich set of libraries (Framework Class Libraries) available to all .NET languages The .NET languages such as C#, VB.NET etc that conform to CLR ASP.NET is how the Framework is exposed to the web, using IIS to manage simple pages of code so that they can be complied into full .NET programs. These generate HTML for the browser.
Built on open protocols (XML, SOAP) Future for development of MS & non-MS based systems. Also heading towards the Internet Operating System
C#
VB
C++
Compilers
Runtime Environment
IL can be verified to guarantee type-safety No unsafe casts, no uninitialized variables, no out-of-bounds array indexing
Evidence-based security
Native Code
IL
Native Code
The compiled code is transformed into an intermediate language called the Microsoft Intermediate Language (MSIL or IL) An integer in Visual Basic .NET or an int in C# are converted to the same .NET data type, which is Int32 The IL that is created is the same for all languages The assembly is the compiled .NET program The assembly contains the IL along with additional information called metadata Metadata contains information about the assembly Use the IL Disassembler (ildasm.exe) to view the IL within an assembly
Framework Overview
VB C++ C# JScript
Win Forms
System Base Framework ADO.NET IO XML Net SQL Security Threading ServiceProcess
Namespace
The base class libraries are organized into logical groupings of code called namespaces A namespace is a hierarchical way to identify resources in .NET The System object is at the top of the namespace hierarchy, and all objects inherit from it
ASP.NET: System.Web namespace WebForms: System.Web.UI namespace HTML Server Controls: System.Web.UI.Control.HTMLControl ASP.NET Server Controls: System.Web.UI.Control.WebControl
Importing Namespaces
Visual Studio .NET adds references to your projects commonly used namespaces by default You can import the namespaces into your page using the @Import directive The following is the syntax for importing a .NET namespace
<%@ Import NamespaceName %>
Below is a sample of how you would import the ASP.NET Page class
<%@ Imports System.Web.UI.Page %>
Support browser/server communication System.Web.UI Creates the Page object whenever an .aspx page is requested System.Web.UI.web Classes and definitions to create controls server controls
ASP.NET
The latest version of ASP is known as ASP.NET Visual Studio .NET is a developer application used to create ASP.NET Web applications There are two main types of Web resources created with ASP.NET applications
WebForms are ASP.NET pages within an ASP.NET application Web Services are ASP.NET Web pages that contain publicly exposed code so that other applications can interact with them Web Services are identified with the file extension .asmx
WebForms
The ASP.NET WebForm is separated into two logical areas:
The HTML template A collection of code behind the WebForm
Server Controls
HTML Server controls are similar to the HTML controls, except they are processed by the server Add runat = "server" to the HTML control to transform it into an HTML Server control HTML control: <input type="text"> HTML Server control:
<input type="text" runat="server"/> <input type=radio runat=server value=Yes/> Yes
Server-side programs can interact with the control before it is rendered as a plain HTML control and sent to the browser
ASP.NET Controls
ASP.NET form controls will create the HTML code ASP.NET Server controls are organized as:
ASP.NET Form Controls Data Validation Controls User Controls Mobile Controls
ASP.NET controls are usually identified with the prefix asp: followed by the name of the control ASP.NET button:
<asp:Button id="ShowBtn" runat="server" Text="Show the message." />
ASP.NET form controls also have different properties than their HTML server control counterparts
HTML Server label control
Message1.InnerHTML = "Product 1"
User Controls
User controls are external files that can be included within another WebForm User controls allow you to reuse code across multiple files For example, you can create a user control that displays the a navigation bar You can use this control on the home page; they are often used for creating self-contained code, headers, menus, and footers User controls replace the functionality of ASP server-side include pages They are identified with the file extension .asmx
Mobile controls
A series of controls that provide form functionality within wireless and mobile devices
Literal controls
Page content that is not assigned to a specific HTML control such as a combination of HTML tags and text to the browser
The @Page directive allows you to set the default properties for the entire page such as the default language The CodeBehind property identifies the path and filename of the code behind file The Inherits property indicates that the code behind the page inherits the page class This page class contains the compiled code for this page
Web Services
Web Services also provide a means to expose .NET functionality on the web but Web Services expose functionality via XML and SOAP (cf: function calls over the web)
If your business partner is Course Technology and you want to query that companys product catalog from your Web site, you could:
Post a link Scrape a Web site (use a program to view a Web site and capture the source code) Provide a Web Service to their catalog application
Web Services
ASP.NET samples
Page directives: <%@ page language = VB debug="true" trace="true %> <script language = VB runat=server> VB.NET code declarations .. </script> Message.aspx
<html> <head> <title>Inserting ASP.NET code Example</title> </head> <body> Line1: First HTML Line<br /> Line2: Second HTML Line<br /> Line3: Third HTML Line<br /> </body> </html> Note this has no asp code so better to use .html extension
Message2.aspx
<script language="VB" runat="server"> Sub Page_Load() Response.Write ("First ASP.NET Line<br />") Response.Write ("Second ASP.NET Line<br />") Response.Write ("Third ASP.NET Line<br />") End Sub </script> <html> <head> <title>Inserting ASP.NET code Example</TITLE> </head> <body> Line1: First HTML Line<br /> Line2: Second HTML Line<br /> Line3: Third HTML Line<br /> </body> </html>
Message3.aspx
html> <head><title>Inserting ASP.NET code Example</title></head> <body> Line1: First HTML Line<br /> Line2: Second HTML Line<br /> Line3: Third HTML Line<br /> <script language="VB" runat="server"> Sub Page_Load() Response.Write ("First ASP.NET Line<br />") Response.Write ("Second ASP.NET Line<br />") Response.Write ("Third ASP.NET Line<br />") End Sub </script> </body> </html>
Global.asax
Global.asax.resx
Global.asax.vb
Project.sln Project.suo
Project.vbproj
Event handler commands visible to all web forms in a project Define application resources such as text strings, images. Can change without recompiling project. Asp.net code for application events eg session.start Stores links to all project files VS.NET IDE configuration info for the proj.
Configuration and build settings for project files.
Project style sheet Project and folder configuration information Web form .aspx file;Html Resources in corresponding web form
Code written for the form (code behind)
Bin\project.dll
Bin\project.pdb
Examples
quickstart webforms
Intro4 shows VIEWSTATE Intro6 shows a click event Intro7 shows a usercontrol with a calander Intro8 shows a db connection Intro9 & 10 show asp.net templates Intro11shows validation controls Intro13 shows code behind pages
ASP.NET Vs PHP
Feature PHP ASP.NET
HTML
CSS php Templates
ServerControls (buttons,grids etc)
Yes
Yes Yes No Yes Yes Yes No No
Yes
Yes UserControls Yes Yes + Validation controls Yes Yes Yes Yes
VIEWSTATE POSTBACK