Week1 PDF
Week1 PDF
Internet Programming II
2
What is ASP.NET?
Technology that provides services to allow for the creation,
deployment, and execution of Web Applications and Web Services
Built on .NET Framework: any .NET programming language can be
used (C#, VB.Net)
Object-oriented model
Separation of code and UI
Maintains page state
Session management
Support for Caching
Debugging
Embedding external libraries in VS
and much more…
3
ASP.NET Versions
– 1.0 – the initial release (2002)
– 1.1 – included a new version of Visual Studio .NET;
no major changes in ASP.NET (2003)
– 2.0 – a wide array of new ASP.NET features and
functionality, along with many new features in the
.NET Framework; included new versions of Visual
Studio and SQL Server (2005)
– 3.0 / 3.5
– 4.0
– 4.5
– 4.5.1 / 4.5.2
– 4.6,
– 4.6.1
– 4.7.2, 4.8
– Versions: https://goo.gl/VpOkJy 4
Installing VS2013/15/17/19
• Visual Studio can target: [Compatibility]
– ASP.NET 2.0
– ASP.NET 3.0
– ASP.NET 3.5
– ASP.NET 4.0
– ASP.NET 4.5
– ASP.NET 4.5.1, 4.5.2, etc…
• https://visualstudio.microsoft.com/downloads/
6
Using HTTP in Web Applications
• This text-based, request-response protocol defines
how web browsers and web servers communicate
with each other:
– HTTP Requests
– HTTP Response
7
Client/Server Architecture for Web Applications
ZOOM IN
Internet
.asp
Examine ASP Engine
REQUEST Extension
.aspx
ASP.NET Engine
IIS 9
Role of global.asax in Life Cycle Events
• File-based website
• Local IIS HTTP
• Remote IIS HTTP
• FTP
11
ASP.NET and the .NET Framework
12
Understanding the Framework Class Library
o Random class
o Graphics class
o SmtpClient class
o File class
Imports System.Data
13
Understanding the Framework Class Library
• The .NET Framework includes around 18,619 types; 12,909 classes; 401,759
public methods; 93,105 public properties; and 30,546 public events.
• Each class in the Framework can include properties, methods, and events. For
example, here is a partial list of the members of the SmtpClient class:
• Properties
– Host: The name or IP address of your email server
– Port: number of the port to use when sending email message
• Methods
– Send: Enables you to send an email message synchronously
– SendAsync: send an email message asynchronously
• Events
– SendCompleted: Raised when an asynchronous send operation completes
14
Understanding Namespaces
• A namespace is simply a category. For example, all
the classes related to working with the file system are
located in the System.IO namespace.
System.IO.File.Exists("SomeFile.txt")
16
Understanding Namespaces
• Specifying a namespace each and every time you use
a class can quickly become tedious. A second option
is to import a namespace.
20
Understanding the Common Language Runtime
21
More about CLR
• The CLR manages execution of .NET programs
– all .NET applications use the same data types regardless of the
programming language used.
22
Understanding the ASP.NET Page Structure
An ASP.NET page has:
• Directives
• Server-side Code [optional]
• Layout
23
Differentiating In-Line Coding and Code-Behind
Programming
• In-Line coding contains all the code and markup in
a single file.
24
Dynamic Pages: Stateless
• A dynamic page is generated each time it is called
• Nevertheless, the page itself is stateless, i.e., it will not maintain the
value of a variable between each loading of the page
26
Visual Studio IDE
27
Demo: welcome.aspx
• Let’s create our first Web page using Visual Studio
1. Modify title of the page
2. Add a heading <h2>
3. Look at the page in Design and Split modes
4. To add controls to the page, you can drag and drop them from the
Toolbox onto the Web Form in Design mode.
Add a Label control from the Toolbox
5. Change ID of the Label control
6. Change some physical properties of the Label control
7. Add a Page_Load event to set the Text property of the Label
control to “Welcome to Visual Studio” (to add in code-behind)
28
Demo: welcome.aspx
• Modify the Title property in the Properties window (F4)
• Like the Web Form itself, each control is an object that has
properties, methods and events: change backcolor (black) and
forecolor (yellow) of the Label
• Page Directive <%@ … %>
• AutoEventWireup attribute
• The Label generates a <span> tag
29
Demo: Running the Program
• You can view the Web Form several ways.
– You can select Debug > Start Without Debugging, which runs
the application by opening it in a browser window.
– To debug your application, you can select Debug > Start
Debugging (F5) You cannot debug a web application unless
debugging is explicitly enabled by the web.config file.
– To view a specific ASPX file, you can right click either the Web
Forms Designer or the ASPX file name and select View In
Browser.
– Finally, you can run your application by opening a browser
window and typing the web page’s URL in the Address field.
30
Demo: Event Handling [datetime.aspx]
• Let’s create another Web page using Visual Studio
1. Add a Button (btnDateTime) and a Label control (lblresult)
2. To create this click event handler, double click the
Button on the Form.
3. Note: an empty event handler is created
4. Set the Text property of the Label control with the current date time.
33
Recap