Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Web Application Development Using ASP.

NET
Lectures & Exercises

CHAPTER I: INTRODUCTION TO ASP.NET

1.1 What is ASP.NET

 is a server side scripting technology that enables scripts (embedded in web pages)
to be executed by an Internet server.
 ASP stands for Active Server Pages
 web programming technology developed by Microsoft
 ASP.NET is a program that runs inside IIS
 IIS (Internet Information Services) is Microsoft's Internet server
 IIS comes as a free component with Windows servers
 used to create dynamic web pages
 successor to ASP

1.1.1 Benefits of using ASP.NET


 Code-behind support
 Code can be compiled from any Microsoft.NET-compatible language
 ASP.NET pages run side-by-side with ASP
 Automatic support for multiple browsers
 ASP.NET namespaces provide rich functionality
 Built-in support for web services

1.2 What is an ASP.NET File


 An ASP.NET file is just the same as an HTML file
 An ASP.NET file can contain HTML, XML, and scripts
 Scripts in an ASP.NET file are executed on the server
 An ASP.NET file has the file extension ".aspx"

By: Jefferson A. Costales, MIT, IBM -CDA, MCTS, ZCE, OCE Chapter 1 of 8
Web Application Development Using ASP.NET
Lectures & Exercises

1.2.1 How Does ASP.NET Work


 When a browser requests an HTML file, the server returns the file
 When a browser requests an ASP.NET file, IIS passes the request to the
ASP.NET engine on the server
 The ASP.NET engine reads the file, line by line, and executes the scripts in the file
 Finally, the ASP.NET file is returned to the browser as plain HTML

1.3 The Microsoft .NET Framework


 The .NET Framework is the infrastructure for the Microsoft .NET platform.
 The .NET Framework is an environment for building, deploying, and running Web
applications and Web Services.
 Microsoft's first server technology ASP (Active Server Pages), was a powerful and
flexible "programming language". But it was too code oriented. It was not an
application framework and not an enterprise development tool.

1.4 The Microsoft .NET Framework was developed to solve this problem through
.NET Frameworks keywords:
 Easier and quicker programming
 Reduced amount of code
 Declarative programming model
 Richer server control hierarchy with events
 Larger class library
 Better support for development tools

1.4.1 The .NET Framework consists of 3 main parts:


 Programming languages:
 C# (Pronounced C sharp
 Visual Basic (VB .NET)
 J# (Pronounced J sharp)

By: Jefferson A. Costales, MIT, IBM -CDA, MCTS, ZCE, OCE Chapter 1 of 8
Web Application Development Using ASP.NET
Lectures & Exercises

1.5 Server technologies and client technologies:


 ASP .NET (Active Server Pages)
 Windows Forms (Windows desktop solutions)
 Compact Framework (PDA / Mobile solutions)

1.5.1 Development environments:


 Visual Studio .NET (VS .NET)
 Visual Web Developer

1.6 ASP.Net Page Structure


 An ASP.Net page consists of the following elements:
 Directives
 Code declaration blocks
 Code render blocks
 ASP.Net server controls
 Server-side comments
 Server-side include directives
 Literal text and HTML tags

 Not every element always appears on a given page, we will learn when to use
them

By: Jefferson A. Costales, MIT, IBM -CDA, MCTS, ZCE, OCE Chapter 1 of 8
Web Application Development Using ASP.NET
Lectures & Exercises

1.6.1 Directives
 Control how the page is compiled
 Specify settings when transferring between pages
 Aid in debugging
 Allow importing of classes
 Start with the <@ sequence and end with a %> sequence
 ASP.Net directives can appear anywhere on the page, but are usually placed as
the first lines in the file

1.6.1.2 Three Common Directives


 The Page directive defines page-specific attributes like the language to be used as
in:
 <%@ Page Language=“C#” %>

 The Import directive makes functionality defined elsewhere through the use of
namespaces as in:
 <%@ Import Namespace=“System.Web.Mail” %>
 The Register directive links a user control to the ASP.Net page as in:
 <%@ Register TagPrefix=“ux” TagName=“footer” Src=“footer.ascx” %>

1.6.2 Code Declaration Blocks


 When you add programming logic to your .aspx page, it resides inside a
<script runat=“server”> tag
 Code declaration tags usually are placed in the <head> of your ASP.Net page
 If you don’t specify the language of the code, it will default to the language in the
Page directive
 <script runat=“server” language=“C#”>

By: Jefferson A. Costales, MIT, IBM -CDA, MCTS, ZCE, OCE Chapter 1 of 8
Web Application Development Using ASP.NET
Lectures & Exercises

1.6.3 Code Render Blocks


 Used to define inline code or inline expressions
 <% String Title = “Harry Potter”; %>
 <% Title %>
 The first line contains a complete line of C# code, the declaration and assignment
of a String variable
 The second line writes out the Title variable onto the page

1.6.4 ASP.Net Server Controls


 Server Controls represent the dynamic elements users interact with.
 There are four types of server controls:
 HTML Controls
 ASP.Net Controls
 Validation Controls
 User Controls
 Most server controls must reside within a <form runat=“server> tag

1.6.4.1 Advantages of Server Controls


 HTML elements can be accessed from within code to change their characteristics,
check their values, or dynamically update them
 ASP.Net controls retain their properties even after the page was processed. This
process is called the View State
 With ASP.Net controls, developers can separate the presentational elements and
the application logic so they can be considered separately

By: Jefferson A. Costales, MIT, IBM -CDA, MCTS, ZCE, OCE Chapter 1 of 8
Web Application Development Using ASP.NET
Lectures & Exercises

1.6.4.2 What is the View State


 The persistence of data after it is sent to the server for processing is possible
because of the View State
 If you have created forms using HTML controls, you have experienced the loss of
data after form submission
 The data is maintained in the view state by encrypting it within a hidden form field

1.6.4.3 Looking at the View State


 Look at the source code of the file after the page has been submitted to see code
similar to this.
 i.e. <input type= hidden” name=“VIEWSTATE”
value=“dWtMTcy0TAy0DawNzt)PDtsPGk6Mj47PjtsPHQ802w8aTWzPj+02
wPGw5uAXJdGFaGaxk6t4=“ />
 The View State is enabled for every page by default
 If you don’t intend to use the View State, set the EnableViewState property of the
Page directive to be false
 <%@ Page EnableViewState=“False” %>

1.6.5 Server-Side Comments


 Server-side comments will not be processed by ASP.Net
 It used the <%-- beginning sequence and the --%> ending sequence
 <% -- This is a server-side comment --%>

 The difference between HTML comments and ASP.Net comments is that ASP.Net
comments are processed by the browser or the ASP.Net runtime
 Don’t use HTML comments to comment out ASP.Net code
 HTML comments only hide things from the browser

By: Jefferson A. Costales, MIT, IBM -CDA, MCTS, ZCE, OCE Chapter 1 of 8
Web Application Development Using ASP.NET
Lectures & Exercises

1.6.6 Server-Side Include Directives


 These includes help developers insert segments of code into a page from an
external file
 There are two techniques for doing this:
 Using the file attribute, we give the physical path to the file on the server
either as an absolute path starting from the drive letter or a relative path to
the current file
 <! -- include file=“myinclude.aspx” --> (relative path)
 Using the virtual attribute, you can specify the file’s location from the
absolute root of the site, or from a relative path to the current page.
 <! -- include virtual=“/directory1/myinclude.aspx” --> (absolute path)

1.6.7 Literal Text and HTML Tags


 One cannot do without text and HTML elements to display information from your
ASP.Net controls and programming code
 Without these there would be no format to the page
 The surrounding <html>, <head>, and <body> tags make it possible for a browser
to understand our page

1.7 Microsoft ASP.NET Languages


 .Net supports many different languages
 Programmers used to VBScript or JavaScript to do their programming will have
more robust, strongly-typed, and feature-rich choices in VB.Net and C#.Net
 VB.Net builds on the RAD (Rapid Application Development) that became
popular in the 90’s. VB.Net is easy to read, use and maintain.

 C#.Net was developed to keep the simplicity of VB and the power and
flexibility of C++ (some say to replace Java). C# does away with confusing
C++ syntax.

By: Jefferson A. Costales, MIT, IBM -CDA, MCTS, ZCE, OCE Chapter 1 of 8
Web Application Development Using ASP.NET
Lectures & Exercises

Exercise No. 1 Grade: ______________

Time: ____Minutes Time Started: ________


Directory Folder: C:\inetpub\wwwroot\LNFNMI\ Time Finished: ________
File Name: Exer1FeedbackFrm.aspx

Write a program to display the following feedback form. The different options for

the list box must be ASP.NET, PHP, VB.NET, and C#.

When the Submit Form button is clicked after entering the data, a message as

seen in the last line of the above figure must be displayed.

Use validation controls to validate the form.

By: Jefferson A. Costales, MIT, IBM -CDA, MCTS, ZCE, OCE Chapter 1 of 8

You might also like