Sie sind auf Seite 1von 40

Introducing ASP.

NET

Pre-Assessment Questions
1. In .NET, codes are compiled into ________.

a. ByteCode
b. Microsoft International Language
c. BitCode
d. Microsoft Intermediate Language

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 1 of 40


Introducing ASP.NET

Pre-Assessment Questions (Contd.)


1. The capability of a derived class to hide the characteristics of the parent
class is called:

a. Overloading
b. Overriding
c. Inheritance
d. Structured programming

3. Which of the following is a property of the StatusBar control?


a. ShowPanels
b. Caption
c. Multiline
d. Autosize

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 2 of 40


Introducing ASP.NET

Pre-Assessment Questions (Contd.)


1. What is the maximum number of characters that you can enter in a
TextBox control?
a. 1024
b. 2048
c. 65
d. 20

2. Which of the following is a feature provided by the Common Language


Runtime (CLR)?
a. Extensibility
b. Resilience to change
c. Automatic memory management
d. Maintainability

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 3 of 40


Introducing ASP.NET

Solutions to Pre –Assessment


Questions
1. d. Microsoft Intermediate Language
2. b. Overriding
3. a. ShowPanels
4. b. 2048
5. c . Automatic memory management

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 4 of 40


Introducing ASP.NET

Objectives
In this lesson, you will learn to:

• Identify the components of dynamic Web applications


• Identify the features of ASP.NET
• Describe the working of an ASP.NET application
• Identify the files used in ASP.NET Web applications
• Identify the events associated with a Web page
• Identify the structure of an ASP.NET page
• Identify the intrinsic objects of ASP.NET
• Implement Cascading Style Sheets on ASP.NET pages

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 5 of 40


Introducing ASP.NET

Introducing Web Applications


• Web applications:
• Are programs that can be executed either on a Web server or in a Web
browser.
• Enable you to share and access information over the Internet and
corporate intranets.
• Can support online commercial transactions, popularly known as e-
commerce.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 6 of 40


Introducing ASP.NET

Components of Dynamic Web


Applications
• An optimal dynamic Web page combines both client-side scripting and server-
side scripting.
• Client-side scripting:
• Enables to develop Web pages that can dynamically respond to user input
without having to interact with a Web server.
• Helps in reducing network traffic.
• Speeds up the response time of a Web application.
• Server-side scripting provides dynamic content to users based on the
information stored in a remote location.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 7 of 40


Introducing ASP.NET

Components of Dynamic Web


Applications (Contd.)
• The general rules for using client side scripting and server-side scripting are:
• Any access to data that resides on the client computer or is dependent on
the client computer should be implemented using client-side scripting.
• Any access to data that resides on a Web server or a remote computer,
such as a back-end database should be implemented using server-side
scripting.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 8 of 40


Introducing ASP.NET

Understanding ASP.NET
• ASP.NET is a standard HTML file that contains embedded server-side scripts.
• ASP.NET provides the following advantages of server-side scripting:
• Enables to access information from data sources that are stored on a Web
server or a computer that is accessible to a Web server
• Enables to use a set of programming code called templates to create HTML
documents
• Enables to separate HTML design from the data retrieval mechanism

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 9 of 40


Introducing ASP.NET

ASP.NET in .NET Framework


• ASP.NET is built on Microsoft .NET Framework.

• Microsoft introduced the .NET Framework to help developers create globally


distributed software with Internet functionality and interoperability.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 10 of 40


Introducing ASP.NET

ASP.NET in .NET Framework (Contd.)


• The following figure illustrates the elements of an ASP.NET application:

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 11 of 40


Introducing ASP.NET

Working of an ASP.NET Application


• After you create an ASP.NET application, the ASP.NET files need to be stored
on an IIS server, which is the Web server for the Windows platform.
• The following figure describes how an IIS server processes the request for an
ASP.NET file:

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 12 of 40


Introducing ASP.NET

Working of an ASP.NET Application


(Contd.)
• The steps to execute an ASP.NET file are as follows:
• A Web browser sends a request for an ASP.NET file to a Web server by
using a URL.
• The Web server receives the request and retrieves the appropriate
ASP.NET file from the disk or memory.
• The Web server forwards the ASP.NET file to the ASP.NET script engine for
processing.
• The ASP.NET script engine reads the file from top to bottom and executes
any server-side script it encounters.
• The processed ASP.NET file is generated as an HTML document and the
ASP.NET script engine sends the HTML page to the Web server.
• The Web server then sends the HTML page to the client.
• The Web browser interprets the output and displays it.
©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 13 of 40
Introducing ASP.NET

Features of ASP.NET
• The features of ASP.NET are as follows:
• Compiled Code
• Enriched Tool Support
• Power and Flexibility
• Simplicity
• Manageability
• Scalability
• Security
• Extensibility

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 14 of 40


Introducing ASP.NET

Programming Models in ASP.NET


• The two types of programming models in ASP.NET are as follows:

• Web Forms
• Web Services

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 15 of 40


Introducing ASP.NET

Programming Models in ASP.NET


(Contd.)
• Web forms:
• Enable you to create the user interface for a Web application.
• Can be designed and programmed using Rapid Application Development
(RAD) tools.
• Support a rich set of controls, including user-defined and third party
controls that make the application user-friendly.
• Web Forms consist of a user interface and application logic that is applied
to the components of user interfaces.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 16 of 40


Introducing ASP.NET

Programming Models in ASP.NET


(Contd.)
• Web Service:
• Is defined as a program unit that can be accessed by other applications
through the Internet.
• Can be called by any application over Hypertext Transfer Protocol (HTTP).
• Make use of Extensible Markup Language to transfer data through HTTP.
• Combine the features of component-based development and the Web
based applications.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 17 of 40


Introducing ASP.NET

Creating an ASP.NET Application


Using Visual Studio .NET IDE
• To create an ASP.NET application, the following steps are performed:
• Select the StartProgramsMicrosoft Visual Studio .NET
Microsoft Visual Studio .NET 2003 command to open the Start Page
of the Visual Studio .NET IDE.
• Select the FileNewProject command to open the New Project
dialog box.
• Select Visual C# Projects as the Project Types in the left pane and
then select ASP.NET Web Application in the Templates pane. Click the
OK button.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 18 of 40


Introducing ASP.NET

Creating an ASP.NET Application


Using Visual Studio .NET IDE (Contd.)
• WebForm1.aspx is displayed in the Design mode. You can add controls
to WebForm1.aspx from the Toolbox by using the drag-drop method.
• Open the Code Editor window by double-clicking Web Form1.aspx in the
Design mode and add the required lines of code for the event handlers.
• Execute the application by selecting Start from the Debug menu.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 19 of 40


Introducing ASP.NET

Files Used in an ASP.NET Application


• When you create an ASP.NET application, the following files get created:
• AssemblyInfo.cs
• Global.asax
• Web.config
• WebApplication.vsdisco
• WebForm1.aspx

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 20 of 40


Introducing ASP.NET

Views of an ASP.NET Application in


the Visual Studio .NET IDE
• Visual Studio .NET IDE provides the following two views of a Web Form:
• Design view
• HTML view

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 21 of 40


Introducing ASP.NET

Code-Behind Feature of ASP.NET


• The code-behind feature enables to divide an ASP.NET page into two files.
• .aspx file containing the presentation content.
• .cs file containing all the application logic, which is called the code-
behind file.

• The advantages of code-behind feature are as follows:


• Makes the code easy to understand and debug, by separating
application logic from HTML tags.
• Allows the separation of effort between graphic designers who design
pages and software engineers who write code.
• Eliminates the issues of browser incompatibility by allowing code files
to exist on the Web server and supporting Web pages to be compiled
on demand.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 22 of 40


Introducing ASP.NET

Code-Behind Feature of ASP.NET


(Contd.)
• In the presentation (.aspx) file and the code-behind (.cs) file, ASP.NET
automatically generates some lines of code.
• In the HTML mode, the first line of an .aspx file contains the following line of
code:
<%@ Page language="c#“
Codebehind="WebForm1.aspx.cs"AutoEventWireup="false“
Inherits="WebApplication1.WebForm1"%>
• The @ Page directive is used to specify the page attributes based on which a
page will be created. The different page attributes are:
• Language
• AutoEventWireup
• Codebehind
• Inherits

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 23 of 40


Introducing ASP.NET

Code-Behind Feature of ASP.NET


(Contd.)
• The code-behind file starts with a list of namespaces.

Namespace Description
System Contains classes for implementing base data
types. In addition, it contains classes for working
with date and time.
System.Collections Contains classes for working with standard
collection types, such as hash tables and array
lists.
System.ComponentModel Contains classes for implementing both design-
time and run-time behaviors of components and
controls.
System.Data Contains classes for implementing the ADO.NET
architecture.
©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 24 of 40
Introducing ASP.NET

Code-Behind Feature of ASP.NET


(Contd.)
Namespace Descriptions
System.Drawing Contains classes for providing access to GDI
+ basic graphics functionality and
manipulating the contents of strings.
System.Web Contains classes and interfaces that enable
browser/server communication.
System.Web.SessionState Contains classes for implementing session
states.
System.Web.UI Contains the base classes used in building
the user interfaces of the ASP.NET page.
System.Web.UI.WebControls Contains classes for providing Web controls.
System.Web.UI.HtmlControls Contains classes for providing HTML controls.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 25 of 40


Introducing ASP.NET

Page Events
• ASP.NET uses an event-driven model of programming. The following table
lists some of these events:

Event Generated when


Init Is the first event that occurs when the server executes an
ASP.NET page. The initialization is performed during this
event. Init event occurs only once in the entire life cycle
of an ASP.NET page
Load Is fired after the init event, when the page is requested
for the first time and whenever the page is reloaded. This
event can be used to initialize the variables and the state
of the controls that are used in the page.
Unload Is the last event that occurs in the life cycle of an
ASP.NET page. This event is used to perform final cleanup
work, such as the closing of open database connections,
discarding objects, or closing the files.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 26 of 40


Introducing ASP.NET

Intrinsic Objects of ASP.NET


• ASP.NET has a number of built-in objects that run on a Web server
• The following table lists the ASP.NET built-in objects and their description:

Object Description
Application Provides methods and properties to access information
related to the entire Web application. Information is
stored in either variables or objects.
Request Provides methods, properties, and collections to access
the information about the client requesting the page.
Response Provides methods, properties, and collections to access
information related to the response generated by the
server.
Server Provides methods and properties to access information
related to the server.
Session Provides methods, properties, and collections to access
information related to the user’s session.
©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 27 of 40
Introducing ASP.NET

Structure of an ASP.NET Page


• The structure of an ASP.NET page includes:

• Directives
• Code declaration blocks
• Code render blocks
• Server-side comments
• Server-side Include directives

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 28 of 40


Introducing ASP.NET

Cascading Style Sheets


• Styles define the appearance of an HTML element.

• A style sheet is a document, which defines a group of styles. Each style in


the group has its own properties.

• Styles can be applied to any element in the web page.

• The style definition consists of a property name followed by a property


value. The property name and value are separated by a colon.

• Multiple properties may be specified by property name-value pairs,


separated by semicolons.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 29 of 40


Introducing ASP.NET

Different Ways to Use Style Sheets


• The three different ways to add style sheet properties to a document are as
follows:

• Using an external (linked ) style sheet


• Using an embedded style sheet
• Using an inline style sheet

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 30 of 40


Introducing ASP.NET

Different Ways to Use Style Sheets


(Contd.)
• External (Linked) Style Sheets

• The style definitions in an external style sheet are stored in a separate


file with the extension .CSS.
• Only the <STYLE>…</STYLE> tags should present in .CSS file and
the style definitions are defined inside these tags.
• Consider the sample code that describes the .CSS file:
<STYLE>
H1 { font-style:italic;background:yellow;color:red
}
P { background:purple}
</STYLE>

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 31 of 40


Introducing ASP.NET

Different Ways to Use Style Sheets


(Contd.)
• Embedded Style Sheets
• Style definitions are included in the HTML page itself.
• The following example code shows an embedded style sheet:
<HEAD><TITLE>
An Embedded Style
</TITLE>
<STYLE TYPE="text/css">
H1 { font-style:italic;background:yellow;color:red }
</STYLE></HEAD>
• A HTML page can contains both external and embedded style sheet
associated with it.
• The style definition for a particular element in the embedded style
sheet will override the style definition in the external style sheet for the
same element.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 32 of 40


Introducing ASP.NET

Different Ways to Use Style Sheets


(Contd.)
• Inline Style Sheets
• Inline styles are style definitions applied to the style property of an
element.
• The following example code shows an embedded style sheet:
<HTML> <BODY>
<P style="font-family:arial;font-style:italic">
This came from a P tag with a style.<BR>
font-family:arial and font-style:italic
</P> <P>
This came from a P tag without a style.
</P> </BODY></HTML>
• The inline or embedded styles will override the properties, which are
specified in the external style sheet.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 33 of 40


Introducing ASP.NET

Demonstration-Creating a Web Form


In ASP.NET
• Problem Statement

• The WebShoppe Mall has decided to launch the WebShoppe


Web site. The WebShoppe wants you to design the new user
sign-up form to register the new users for accessing the
WebShoppe Web site. The sign-up form should have the first
name, last name, user name, password, confirm password,
address, city, state, postal code, country, telephone number,
and e-mail id fields. The form should display a welcome
message when the registration is successful.
Hint: Apply styles using CSS to enhance the Web form.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 34 of 40


Introducing ASP.NET

Demonstration-Creating a Web Form


In ASP.NET (Contd.)
• Solution

1. Create an ASP.NET Web application.


2. Design a Web form.
3. Add a style sheet to the WebShoppeSite project.
4. Redirect a page.
5. Run the application.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 35 of 40


Introducing ASP.NET

Summary
In this lesson, you learned that:
• A Web application can have client-side scripting, server-side scripting, or both.
• ASP.NET, the .NET version of ASP, is built on Microsoft .NET Framework. After
creating an ASP.NET application, the ASP.NET files need to be stored on the IIS
server.
• The features of ASP.NET are:
• Compiled Code
• Enriched Tool Support
• Power and Flexibility
• Simplicity
• Manageability
• Scalability
• Security
• Customizability
• Extensibility

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 36 of 40


Introducing ASP.NET

Summary (Contd.)
• ASP.NET provides two types of programming models:
• Web Forms
• Web Services
• Web Forms enable you to create form-based dynamic Web pages.
• A Web Service is defined as a program unit that can be accessed by other
applications through the Internet.
• The following are the files that get generated when you create an ASP.NET
application:
• AssemblyInfo.cs
• Global.asax
• Web.config
• WebApplication.vsdisco
• WebForm1.aspx

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 37 of 40


Introducing ASP.NET

Summary (Contd.)
• Web forms have two views:
• Design view
• HTML view
• The code-behind feature of ASP.NET enables you to divide an ASP.NET page into
two files:
• The presentation file that stores the user interface contents.
• The code-behind file that stores the application logic.
• The sequence of events that are fired during the life cycle of a Web page are:
• Init
• Load
• Unload

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 38 of 40


Introducing ASP.NET

Summary (Contd.)
• Some of the built-in intrinsic objects are:
• Application
• Request
• Response
• Server
• Session
• The structure of an ASP.NET page includes:
• Directives
• Code declaration blocks
• Code render blocks
• Server-side comments
• Server-side Include directives
• A style sheet is a document, which defines a group of styles.

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 39 of 40


Introducing ASP.NET

Summary (Contd.)
• The three ways to add a style sheet to a Web page are:
• Using an inline style sheet
• Using an embedded style sheet
• Using an external (linked) style sheet

©NIIT Developing Web Applications Using ASP.NET Lesson 1A / Slide 40 of 40

Das könnte Ihnen auch gefallen