asp.net.ppt

57
ASP.NET Web Applications CE050-3-2

Upload: ashi-sharma

Post on 05-May-2017

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: ASP.NET.ppt

ASP.NET

Web ApplicationsCE050-3-2

Page 2: ASP.NET.ppt

Web Applications Slide 2 of 12

ASP.NET

Topic & Structure of the lesson

• Understand Static Web Pages• Understand Dynamic Web Pages• Understand Browser and Web Server• The Microsoft .NET Framework • Introduction to ASP.NET• Classic ASP? • ASP.NET is Not ASP • What is ASP.NET? • ASP.NET File• How Does ASP.NET Work? • Language Support • Object Oriented• Windows and IIS Dependence• A Simple ASP.NET Example

Page 3: ASP.NET.ppt

Web Applications Slide 3 of 12

ASP.NET

Topic & Structure of the lesson

• Visual Studio• Web Forms• ASP.NET Controls• Web Controls• Validation Controls • Event Aware Controls • ASP.NET - Web Pages • A Simple Web Application• The appearance of the Simple Calculator (C#)• The Code-Behind File of the Simple Calculator Application• Creating Your First ASP.NET 2.0 Application• Creating a New Web Site• Adding Pages• Adding Web Controls• Adding Action for Button

Page 4: ASP.NET.ppt

Web Applications Slide 4 of 12

ASP.NET

Learning Outcomes

At the end of the module, your should be able:• To create Web Forms.• To create ASP.NET applications consisting of

multiple Web Forms.• To understand how ASP.NET pages work.• To understand the differences between client-

side scripting and server-side scripting.• To understand Web forms and code-behind files.

Page 5: ASP.NET.ppt

Web Applications Slide 5 of 12

ASP.NET

Key Terms you must be able to use

If you have mastered this topic, you should be able to use the following terms correctly in your assignments and exams:• ASP.NET

– Microsoft's Server-side technology that dynamically builds documents in response to client requests

Page 6: ASP.NET.ppt

Web Applications Slide 6 of 12

ASP.NET

Understand Static Web Pages

• The World Wide Web was originally designed to display static pages — that is, pages that are the same every time they are displayed.

• In fact, many pages available on the Internet today are still static pages.

• They are created using HTML only.

Page 7: ASP.NET.ppt

Web Applications Slide 7 of 12

ASP.NET

Understand Dynamic Web Pages

• Most Web pages these days display dynamic content — that is, content that changes each time the page is retrieved.

• Instead of retrieving HTML data from a file, dynamic Web pages work by running a program that generates the HTML sent back to the browser.

• The program can generate different HTML each time the page is requested.

Page 8: ASP.NET.ppt

Web Applications Slide 8 of 12

ASP.NET

Understand Browser and Web Server

• The client is a Web browser that runs on the end-user’s computer. In most cases, the Web browser is Microsoft Internet Explorer, but other programs such as Mozilla Firefox can be used as the client.

• The server is software that runs on the server computer that hosts the Web application.

• For ASP.NET applications, the server software is always Microsoft Internet Information Services (also known as IIS).

• The server computer must also have Microsoft .NET Framework software installed, as ASP.NET is a part of the .NET Framework.

Page 9: ASP.NET.ppt

Web Applications Slide 9 of 12

ASP.NET

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 applications and Services.

• Microsoft's first server technology ASP (Active Server Pages), was a powerful and flexible "programming language". But it was to much code oriented. It was not an application framework and not an enterprise development tool.

• The Microsoft .NET Framework was developed to solve this problem.

Page 10: ASP.NET.ppt

Web Applications Slide 10 of 12

ASP.NET

The Microsoft .NET Framework

• Manages and executes applications• Framework Class Library (FCL)

– Enforces security and supplies many other programming capabilities

– Reusable components that programmers can incorporate into their applications

• Common Language Runtime (CLR)– Executes programs written in any .NET-compatible

programming language• .NET Compact Framework

Page 11: ASP.NET.ppt

Web Applications Slide 11 of 12

ASP.NET

The Microsoft .NET Framework

The .NET Framework consists of 3 main parts:• Programming languages:

– C# (Pronounced C sharp) – Visual Basic (VB .NET) – J# (Pronounced J sharp)

• Server technologies and client technologies:– ASP .NET (Active Server Pages) – Windows Forms (Windows desktop solutions) – Compact Framework (PDA / Mobile solutions)

• Development environments:– Visual Studio .NET (VS .NET) – Visual Web Developer

Page 12: ASP.NET.ppt

Web Applications Slide 12 of 12

ASP.NET

Introduction to ASP.NET

• ASP.NET– ASP.NET is the latest version of Microsoft's Active

Server Pages technology (ASP).– ASP.NET is a part of the Microsoft .NET framework,

and a powerful tool for creating dynamic and interactive web pages.

– Server-side technology that dynamically builds documents in response to client requests

– Can be used on a server to create Web applications– Web-based applications create Web content for Web

browser clients.

Page 13: ASP.NET.ppt

Web Applications Slide 13 of 12

ASP.NET

Introduction to ASP.NET

• Web-Based Application Development– Creates Web content for Web browser clients

• Extensible HyperText Markup Language (XHTML)• Client-side scripting• Images and binary data

– Web Forms (Web Form pages)• File extension .aspx• ASPX (Web Form files) contain written code, event handlers,

utility methods and other supporting code• Supports over 25 programming languages (C#,

C++, VB, J#...)• Object-oriented programming

Page 14: ASP.NET.ppt

Web Applications Slide 14 of 12

ASP.NET

Introduction to ASP.NET

• Multi-tier, database-intensive applications• Includes optimizations for performance,

testing and security• ASPX files• XHTML documents

– Static

Page 15: ASP.NET.ppt

Web Applications Slide 15 of 12

ASP.NET

Classic ASP?

• Microsoft's previous server side scripting technology ASP (Active Server Pages) is now often called classic ASP.

• ASP 3.0 was the last version of the classic ASP.

Page 16: ASP.NET.ppt

Web Applications Slide 16 of 12

ASP.NET

ASP.NET is Not ASP

• ASP.NET is the next generation ASP, but it's not an upgraded version of ASP.

• ASP.NET is an entirely new technology for server-side scripting. It was written from the ground up and is not backward compatible with classic ASP.

• ASP.NET is the major part of the Microsoft's .NET Framework.

Page 17: ASP.NET.ppt

Web Applications Slide 17 of 12

ASP.NET

What is ASP.NET?

• 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 • 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 • IIS is also a part of Windows 2000 and XP Professional• ASP.NET 2.0 improves upon ASP.NET by adding

support for several new features.

Page 18: ASP.NET.ppt

Web Applications Slide 18 of 12

ASP.NET

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"

Page 19: ASP.NET.ppt

Web Applications Slide 19 of 12

ASP.NET

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

Page 20: ASP.NET.ppt

Web Applications Slide 20 of 12

ASP.NET

Language Support

• ASP.NET uses the new ADO.NET.• ASP.NET supports full Visual Basic, not

VBScript.• ASP.NET supports C# (C Sharp) and C++.• ASP.NET supports J# (J Sharp).• ASP.NET supports JScript as before.

Page 21: ASP.NET.ppt

Web Applications Slide 21 of 12

ASP.NET

Language Support

• Visual Basic .NET: Visual Basic .NET (VB.NET) is a modern version of the venerable Basic programming language. Basic was originally intended as a limited language designed for beginners, but the current version of Visual Basic is as powerful a language as you’ll find.

• C#: C# (pronounced C-Sharp) is a relatively new language designed by Microsoft specifically for .NET. Its syntax is similar to Java, so if you’re an experienced Java programmer, you won’t have much trouble learning C#.

• J#: Microsoft’s version of Java. It isn’t used much for ASP.NET development.

Page 22: ASP.NET.ppt

Web Applications Slide 22 of 12

ASP.NET

Object Oriented

• ASP.NET is inherently object-oriented. • If you’re familiar with programming and• have worked with object-oriented programming

languages such as C++ or Java, you’ll appreciate the benefits immediately.

• A major attraction of ASP.NET’s object orientation is that it allows you to take advantage of a vast library of predefined classes known as the .NET Framework.

Page 23: ASP.NET.ppt

Web Applications Slide 23 of 12

ASP.NET

Windows and IIS Dependence

• ASP.NET will only work on Microsoft Windows–based Web servers.

• That means the operating system must be a recent version of Windows, and the HTTP server software must be Microsoft’s Internet Information Services, also known as IIS.

• Specifically, ASP.NET 2.0 requires the following support software:– Windows 2000 Server (with Service Pack 3) or Windows Server

2003. (For development systems, Windows 2000 with SP3 or Windows XP Professional is required.)

– Internet Information Services 5.0 or later. – Microsoft .NET Framework 2.0

Page 24: ASP.NET.ppt

Web Applications Slide 24 of 12

ASP.NET

A Simple ASP.NET Example

• Scripting delimiters <% and %>– Wrapped around C# or VB.NET code– Compiled and executed on the server– @ Page directive

• Specifies information needed by CLR (Common Language Runtime) to process file

– Language attribute• Specifies C# or VB.NET as scripting language

– runat attribute with value “server”• Indicates script should be processed on server

Page 25: ASP.NET.ppt

Web Applications Slide 25 of 12

ASP.NET

A Simple ASP.NET Example

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>A Simple ASP.NET Example</title></head><body> <strong>A Simple ASP.NET Example</strong><br /> <% Response.Write("ASP.NET programming is fun!!!"); Response.Write("<br />"); Response.Write ("This page was loaded at: " + DateTime.Now.ToString()); %></body></html>

Page 26: ASP.NET.ppt

Web Applications Slide 26 of 12

ASP.NET

A Simple ASP.NET Example

Page 27: ASP.NET.ppt

Web Applications Slide 27 of 12

ASP.NET

A Simple ASP.NET Example

Object Name Description Request Used to access information passed by an

HTTP request. Response Used to control the information sent to the

client. Server Used to access methods and properties on the

server. Commonly used ASP.NET objects.

Page 28: ASP.NET.ppt

Web Applications Slide 28 of 12

ASP.NET

Visual Studio

• One of the best features of ASP.NET is Visual Studio, the integrated development environment that combines a Web-page editor, a code editor, a debugger, and several other development tools into one easy-to-use program.

• The more you work with Visual Studio, the more you come to appreciate the many ways it simplifies the job of creating ASP.NET Web applications.

Page 29: ASP.NET.ppt

Web Applications Slide 29 of 12

ASP.NET

Visual Studio

Properties Panel

Tabs

WebForm

SolutionExplorer

Menu

Page 30: ASP.NET.ppt

Web Applications Slide 30 of 12

ASP.NET

Web Forms

• <form> tag– Designate ASP.NET Web Form

• Web controls– Web server controls

• Form-like controls such as drop-down lists and text boxes– HTML server controls

• Programmable HTML elements run on the server– Validation controls (validators)

• Required field validator• Range validator

– User controls• Created by programmer

Page 31: ASP.NET.ppt

Web Applications Slide 31 of 12

ASP.NET

Web Forms

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> </div> </form></body></html>

Page 32: ASP.NET.ppt

Web Applications Slide 32 of 12

ASP.NET

ASP.NET Controls

• ASP.NET contains a large set of HTML controls. Almost all HTML elements on a page can be defined as ASP.NET control objects that can be controlled by scripts.

• ASP.NET also contains a new set of object oriented input controls, like programmable list boxes and validation controls.

• A new data grid control supports sorting, data paging, and everything you expect from a dataset control.

• The controls use syntax such as the following:

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:Button ID="Button1" runat="server" Text="Button" />

Page 33: ASP.NET.ppt

Web Applications Slide 33 of 12

ASP.NET

Web Controls

• Text and Graphics Control– Label, Button, TextBox, Image RadioButtonList

and DropDownListWeb Control Description Label Displays text that the user cannot edit.

Button Triggers an event when clicked. TextBox Gathers user input and displays text. Image Displays images (e.g., GIF and JPG). RadioButtonList Contains a grouping of radio buttons. DropDownList Displays a drop-down list of choices from which the user can select

one item.

Commonly used Web controls.

Page 34: ASP.NET.ppt

Web Applications Slide 34 of 12

ASP.NET

ASP.NET Controls

Web Controls

Page 35: ASP.NET.ppt

Web Applications Slide 35 of 12

ASP.NET

HTML Server Controls

HTML Server Control

Description

HtmlAnchor Navigation link. HtmlButton Customizable input button. HtmlTable Programmatically built table. HtmlInputFile Handles uploading of files from client to server. HtmlImage Renders images. HtmlForm User-input form. HTML server controls.

Page 36: ASP.NET.ppt

Web Applications Slide 36 of 12

ASP.NET

Validation Controls

• Validation Controls– Determines whether the data in another Web

control are in the proper format• Validates user input

Page 37: ASP.NET.ppt

Web Applications Slide 37 of 12

ASP.NET

Validation Controls

Server Control Description RequiredFieldValidator Checks that the user does not leave a

field blank. CompareValidator Compares an input value with

another value. The value being compared to may be another control’s input value.

RangeValidator Checks that a user’s entry is within a specified range.

RegularExpressionValidator Checks that the entry matches a regular expression pattern.

ValidationSummary Displays the validation errors for all the validation controls on a page.

Validation server controls.

Page 38: ASP.NET.ppt

Web Applications Slide 38 of 12

ASP.NET

Event Aware Controls

• All ASP.NET objects on a Web page can expose events that can be processed by ASP.NET code.

• Load, Click and Change events handled by code makes coding much simpler and much better organized.

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

protected void Button1_Click(object sender, EventArgs e)

{

// Statement

}

Page 39: ASP.NET.ppt

Web Applications Slide 39 of 12

ASP.NET

ASP.NET - Web Pages

• Fundamentally an ASP.NET page is just the same as an HTML page.

• An HTML page has the extension .htm. If a browser requests an HTML page from the server, the server sends the page to the browser without any modifications.

• An ASP.NET page has the extension .aspx. If a browser requests an ASP.NET page, the server processes any executable code in the page, before the result is sent back to the browser.

Page 40: ASP.NET.ppt

Web Applications Slide 40 of 12

ASP.NET

Code-Behind Approach

• Alternative method of adding scripts to make static content dynamic

• Not included in the .aspx file• Must be compiled first• Two source files:

– The markup file (or the .aspx file) defines the appearance of the Web page.

– The code-behind file (or the .aspx.cs or .aspx.vb file)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

Page 41: ASP.NET.ppt

Web Applications Slide 41 of 12

ASP.NET

A Simple Web Application

• To help you understand how a typical ASP.NET application works, the next slide presents a simple calculator application: It lets the user enter two numbers, and when the user then clicks the [Add] button, the application adds up the two numbers and displays the result.

Page 42: ASP.NET.ppt

Web Applications Slide 42 of 12

ASP.NET

A Simple Web Application

Page 43: ASP.NET.ppt

Web Applications Slide 43 of 12

ASP.NET

A Simple Web Application

• The Simple Calculator page includes four controls:– A text box that lets the user enter the first

number to be added.– Another text box that lets the user enter the

second number to be added.– A button the user can click to submit the page

and calculate the sum of the two numbers.– A label that displays the result of the addition.

Page 44: ASP.NET.ppt

Web Applications Slide 44 of 12

ASP.NET

A Simple Web Application

• To develop a single-page ASP.NET application such as the Simple Calculator application, you create two source files:– The markup file (or

the .aspx file) defines the appearance of the Web page.

– The code-behind file (or the .aspx.cs or .aspx.vb file)

Page 45: ASP.NET.ppt

Web Applications Slide 45 of 12

ASP.NET

The appearance of the Simple Calculator (C#)

Page 46: ASP.NET.ppt

Web Applications Slide 46 of 12

ASP.NET

The Code-Behind File of the Simple Calculator Application

Page 47: ASP.NET.ppt

Web Applications Slide 47 of 12

ASP.NET

Creating Your First ASP.NET 2.0 Application

• Visual Studio organizes the files of an ASP.NET application by using logical containers called projects and solutions. – A project is a container that holds all files related to a single

ASP.NET application — including the .aspx files that define the application’s Web pages, the code-behind files that provide the code executed when the application runs, and other files used by the application.

– A solution is a container that can hold one or more projects. Solutions let you group related applications.

– Most solutions contain just a single project. In fact, when you create anew Web application, Visual Studio creates two containers: a project to hold the application’s files and a solution to hold the project.

Page 48: ASP.NET.ppt

Web Applications Slide 48 of 12

ASP.NET

Creating a New Web Site

To create a new Web site in Visual Studio 2005, follow these steps:

1. Choose the File New Web Site command.➪ ➪2. Choose ASP.NET Web Site from the list of available

templates.3. Choose File System, HTTP, or FTP from the Location

drop-down list.4. Enter the location for the Web site in the combo box

that’s to the right of the Location drop-down list.5. Choose the language you want to use to create the

site.6. Click OK.

Page 49: ASP.NET.ppt

Web Applications Slide 49 of 12

ASP.NET

Creating a New Web Site

Page 50: ASP.NET.ppt

Web Applications Slide 50 of 12

ASP.NET

Adding Pages

1. Right Click Website Add New Item.➪2. Make sure Web Form is selected in the

Templates box.3. Enter a name for the page in the Name

text box.4. Select the programming language.5. Make sure the Place Code in Separate

File option is checked.6. Click Add.

Page 51: ASP.NET.ppt

Web Applications Slide 51 of 12

ASP.NET

Adding Pages

Page 52: ASP.NET.ppt

Web Applications Slide 52 of 12

ASP.NET

Adding Web Controls

1. Drag and drop 4 labels, 2 textboxes and 1 button from the toolbox panel to the web form.

2. Change the text for the controls in the properties panel accordingly to produce a page that is same to the figure in next slide.

Page 53: ASP.NET.ppt

Web Applications Slide 53 of 12

ASP.NET

Adding Web Controls

Page 54: ASP.NET.ppt

Web Applications Slide 54 of 12

ASP.NET

Adding Action for Button

1. Double click the Add button on the web form

2. Type the following codes.protected void Button1_Click(object sender, EventArgs e)

{

double result = 0.0;

result = Convert.ToDouble(this.TextBox1.Text)

+ Convert.ToDouble(this.TextBox2.Text);

this.Label4.Text = "The result is: " + result.ToString();

}

Page 55: ASP.NET.ppt

Web Applications Slide 55 of 12

ASP.NET

Adding Action for Button

Page 56: ASP.NET.ppt

Web Applications Slide 56 of 12

ASP.NET

Debugging and Preview in Bowser

• Click the Start Debugging icon or press F5 to debug the codes and preview the web form in browser.

Page 57: ASP.NET.ppt

Web Applications Slide 57 of 12

ASP.NET

Q & A

Question and Answer Session