1. Trang chủ
  2. » Công Nghệ Thông Tin

Module 1: Working with ASP.NET

44 455 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Module 1: Working with ASP.NET
Trường học Microsoft Corporation
Chuyên ngành Computer Science
Thể loại Lecture Module
Năm xuất bản 2000
Thành phố Redmond
Định dạng
Số trang 44
Dung lượng 1,07 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

They will also learn about server controls and see how to add server-side script to an ASP.NET page.. In the lab, students will add HTML server controls to an ASP.NET page, and then add

Trang 1

Contents

Overview 1

Adding ASP.NET Code to a Page 23

Lab 1: Using ASP.NET to Output Text 35

Review 36

Module 1: Working with ASP.NET

Trang 2

to represent any real individual, company, product, or event, unless otherwise noted Complying with all applicable copyright laws is the responsibility of the user No part of this document may

be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without the express written permission of Microsoft Corporation If, however, your only means of access is electronic, permission to print one copy is hereby granted

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property

 2000 Microsoft Corporation All rights reserved

Microsoft, BackOffice, MS-DOS, Windows, Windows NT, <plus other appropriate product names or titles The publications specialist replaces this example list with the list of trademarks provided by the copy editor Microsoft is listed first, followed by all other Microsoft trademarks

in alphabetical order > are either registered trademarks or trademarks of Microsoft Corporation

in the U.S.A and/or other countries

<The publications specialist inserts mention of specific, contractually obligated to, third-party trademarks, provided by the copy editor>

Other product and company names mentioned herein may be the trademarks of their respective owners

Trang 3

Instructor Notes

This module provides students with an overview of ASP.NET Students will learn about the main features of ASP.NET and discover the differences between ASP and ASP.NET They will also learn about server controls and see how to add server-side script to an ASP.NET page

In the lab, students will add HTML server controls to an ASP.NET page, and then add event procedures for the HTML server controls Students will also add event procedures to the page

After completing this module, students will be able to:

! Identify the main features of ASP.NET

! Identify the differences between ASP and ASP.NET

! Describe the working model of ASP.NET

! Describe the architecture of server controls

! Add an HTML server control to a page

! Access the properties and methods of server controls in code

! Add event handlers for page events

! Use the IsPostback property to handle postback forms

Materials and Preparation

This section provides the materials and preparation tasks that you need to teach this module

Required Materials

To teach this module, you need the following materials:

! Microsoft® PowerPoint® file 2063A_01.ppt

! Module 1, “ Working with ASP.NET” (2063A_01.doc)

! Lab, “Using ASP.NET to Output Text” (2063A_L01.doc)

! Animation: ASP.NET Execution Model (2063A_01A001.swf)

Presentation:

120 Minutes

Lab:

30 Minutes

Trang 4

Preparation Tasks

To prepare for this module, you should:

! Read all of the materials for this module

! Complete all the demonstrations

! Complete the lab

! Go through the animation

! Read up material about the NET framework

! Read up material on the various differences between ASP and ASP.NET

Demonstration

This section provides demonstration procedures that will not fit in the margin notes or are not appropriate for the student notes

Adding Server Controls to an ASP.NET Page

! To run this demonstration

1 View the file //localhost/2063/democode/Mod01/server_controls.aspx in Internet Explorer This file has a form with an input box, a list box, and a Submit button When you fill information in the controls and click Submit, the information is lost

2 Edit the page Add a runat="server" attribute to the 3 controls on the page

3 View the page in the browser again View the source of the page to show the changes that were made The controls still lose their values

4 Edi the page and add a runat="server" attribute to the form

5 View the page in the browser again View the source of the page to show the changes that were made The controls now save their values

6 Edit the page and change the controls to intrinsic web controls: asp:textbox, asp:listbox, asp:button

7 View the page in the browser and show the source of the page

Adding Code to Controls

! To run this demonstration

The file 2063\DemoCode\Mod01\eventproc.aspx has the completed code for this demonstration

1 Open the file //2063/democode/mod01/server_controls.aspx

2 Change the controls back to HTML server controls and add ID attributes to the text box and the listbox: txtName and lstTitle

3 Add a span tag to the bottom of the page:

<span style="font: 12pt verdana; color:red;"

id="spnGreeting" runat="server">

4 Add an onServerClick attribute to the button that will call the GreetMe procedure

Trang 5

5 Create a SCRIPT section for server-side code

<SCRIPT language="VB" runat="Server">

6 Create the GreetMe sub procedure

Sub GreetMe(s As Object, e As EventArgs) spnGreeting.InnerHTML = "Hello " & txtName.Value & _ " I see your occupation is " & lstTitle.Value End Sub

7 View the page in Internet Explorer When you click the button the values of the controls are displayed in the span

8 View the source of the page to show that the server-side code is not included in the page

Using PostBack Forms

! To run this demonstration

The file 2063\DemoCode\Mod01\postback.aspx has the completed code for this demonstration

1 Open the file //2063/democode/mod01/server_controls.aspx

2 Add a Page_Load event procedure that initializes the text box

Sub Page_Load(s As Object, e As EventArgs) txtName.Value = "Enter your name"

Trang 6

Multimedia Presentation

This section provides multimedia presentation procedures that do not fit in the margin notes or are not appropriate for the student notes

ASP.NET Execution Model

! To present the animation:

Click First Request This is what happens when an aspx is requested for the

first time

The client sends a request for a page to the ASP.NET server (The request is in the HTTP-GET form) In this animation, the client is requesting the Hello.aspx page The server checks to see whether there is an existing output cache for the requested page, or else if the requested page is already compiled

If there is no output cache or compiled code, the source code for the page is interpreted by a parser, and a compiler is invoked

The compiler loads the page and compiles the code into

an intermediate language (IL)

The compiled IL code is used for returning the requested page to the client

Click Second Request When the client requests for the same page the second

time, the server again checks for an existing output cache

or the compiled code

If the server finds the compiled code, then notice how the compiler step is omitted and the compiled code is straightaway used for returning the request

Click Output Cache This is the other case, when the server finds the requested

page in the output cache In this case notice how all the other steps are bypassed and the requested page is directly returned from the output cache

Trang 7

Module Strategy

Use the following strategy to present this module:

! Introducing ASP.NET This section provides students an overview of the NET framework and how ASP.NET fits in that architecture The focus of this section is the ASP.NET architecture; therefore, avoid getting into too many details about the NET architecture The section also talks about the main features of ASP.NET

Again avoid getting into the details because the following chapters deal with these features in detail After discussing the main features of ASP, ask students to compare it with ASP and come up with a comprehensive list of differences between ASP and ASP.NET

Does not support Web services Includes Web services

This section also includes a demonstration on using VS.NET This demonstration gives them the familiarity with the VS.NET interface

! Server Controls ASP.NET introduces the concept of server controls that encapsulate common tasks and provide a clean programming model This section provides students with an overview of server controls and how to use them

in applications This section also discusses Web controls, but do not get into the details of Web controls as these are discussed in detail in Module 2,

“Using Web Controls”

! Adding ASP.NET Code to a Page ASP.NET introduces a new way of coding that is very similar to coding in event-driven languages In this section, students will learn how to create a basic ASP.NET page In addition, this section also includes a topic on the major differences between Visual Basic 6.0 and Visual Basic.NET Version 7.0

! Page Event Life Cycle This section provides students with information on the life cycle of an ASP.NET page It talks about the main events that are involved in a page life cycle The section also includes information on the use of IsPostBack property for postback forms In the demonstration, show them what will happen if you do not use the IsPostBack property

Trang 9

Overview

! Introducing ASP.NET

! Server Controls

Microsoft's Active Server Pages (ASP) technology is widely used to create dynamic Web sites and applications However, ASP has several limitations, such as the need for redundant and long-winded coding to accomplish simple goals To overcome these limitations of ASP, Microsoft has developed a new technology called ASP.NET, which is a part of the NET strategy for Web development ASP.NET is a unified Web development platform that provides the services necessary for developers to build enterprise-class Web applications

In this module you will learn about the main features of ASP.NET and discover the differences between ASP and ASP.NET You will also learn about server controls and see how to add server-side script to an ASP.NET page

After completing this module, you will be able to:

! Identify the main features of ASP.NET

! Identify the differences between ASP and ASP.NET

! Describe the working model of ASP.NET

! Describe the architecture of server controls

! Add an HTML server control to a page

! Access the properties and methods of server controls in code

! Add event handlers for page events

! Use the IsPostback property to handle postback forms

In this module, you will learn

about the main features of

ASP.NET, and learn how to

add server-side script to an

ASP.NET page

Trang 10

# Introducing ASP.NET

! Demonstration: Using Visual Studio.NET

In this section, you will read an overview of the NET Framework and see how ASP.NET fits in Next, you will learn about the various features of ASP.NET and see a working model You will also learn about the main differences between ASP and ASP.NET

Topic Objective

To introduce the topics

included in the section

Lead-in

Before you start using

ASP.NET, you should have

an overview of ASP.NET

and its framework

Trang 11

The NET Framework

Base Class Library Data Win Forms

Common Language Runtime

Web Forms Web Services

The NET platform provides all the tools and technologies needed to build distributed Web applications It exposes a consistent, language-independent programming model across all tiers of an application, while providing seamless interoperability with and easy migration from existing technologies

The NET platform is composed of several core technologies:

! The NET Framework

! The NET Building Block Services

! The NET Enterprise Servers

! Microsoft Visual Studio.NET

! Microsoft Windows.NET The NET Framework is a set of technologies that is an integral part of the Microsoft NET platform It provides the basic building blocks for developing Web applications and services The NET Framework includes the following components:

! Common Language Runtime

! Base class library

ASP.NET is integrated into

the operating system This

architecture differs

remarkably from earlier

versions of ASP, which were

basically add-ons to the

operating system ASP.NET

is a part of the NET

Framework that supports all

applications in Windows

Trang 12

Common Language Runtime

The Common Language Runtime provides the programming interface between the NET Framework and the programming languages available for the NET platform It simplifies application development, provides a robust and secure execution environment, supports multiple languages, and simplifies application deployment and management The runtime loads and runs code written in any runtime-aware programming language Code that targets the runtime is called managed code Managed code simply means that there is a defined contract of cooperation between natively executing code and the runtime itself

Responsibility for tasks like creating objects, making method calls, and so on is delegated to the runtime, which enables the runtime to provide additional services to the executing code

Base Classes and Libraries

The NET Framework includes classes that encapsulate data structures, perform I/O, give you access to information about a loaded class, and provide a way to invoke security checks It also includes classes that encapsulate exceptions, and other helpful functionality such as data access, server side UI projections and rich GUI generation The NET Framework provides both abstract base classes and class implementations derived from those base classes You can use these derived classes "as is" or derive your own classes from them

The NET Framework classes are named using a dot-syntax naming scheme that connotes a naming hierarchy This technique is used to logically group related classes together so that they can be searched and referenced more easily A grouping of classes is called a namespace For example, your program can use classes in the System.Data.SQL namespace to read data from a SQL Server database

The root namespace for the NET Framework is the System namespace

Data

ADO.NET is the next generation of ActiveX Data Object (ADO) technology ADO.NET provides improved support for the disconnected programming model and also provides rich XML support ADO was created to provide data services to traditional client applications that were tightly coupled to the database; consequently it was not effective for web applications ADO.NET was created with the characteristics of web applications in mind

Web Forms and Web Services

ASP.NET is a programming framework built on the Common Language Runtime that can be used on a server to build powerful Web applications ASP.NET Web forms provide an easy and powerful way to build dynamic user interfaces ASP.NET Web services provide the building blocks for constructing distributed Web-based applications Web services are based on the industry standard SOAP specification

Trang 13

Win Forms

For Windows-based applications, the NET Framework provides the

System.WinForms namespace to create the user interface You can use System.WinForms to do rapid application design (RAD) It provides

inheritance in the same client user interface library You can build components using inheritance and then aggregate them using a form designer such as Microsoft Visual Basic

WinForms will not be covered as part of this class

Trang 14

use the asp extension, ASP.NET pages use the aspx extension

Both ASP and ASP.NET pages can be used in the same Web site Your existing ASP pages will still work along with your new ASP.NET pages, they don't have to be converted into ASP.NET pages

ASP.NET, with a host of new features, allows developers to write cleaner code that is simple to reuse and share ASP.NET boosts performance and scalability

by offering access to complied languages Some of the main features of ASP.NET are described below

Multiple Language Support

ASP.NET provides a true language-neutral execution framework for Web applications

You can currently use over twenty languages to build NET applications Microsoft has compilers for Visual Basic, C#, C++, and JScript Third party vendors are writing NET compilers for Cobol, Pascal, Perl, and Smalltalk, among others

The labs and the sample code in this course will use Visual Basic

Increased Performance

In ASP.NET, code is compiled When the page is requested for the first time, the runtime compiles the code and the page itself and keeps a cached copy of the compiled result The cached copy can be used whenever there is another request for the page This results in greatly increased performance because after this first request, the code can run from the much faster compiled version, and the content on the page doesn’t have to be parsed again

Topic Objective

To describe the main

features of ASP.NET

Lead-in

ASP.NET includes many

features that make

ASP.NET a preferred tool

for Web development

Note

Trang 15

Classes and Namespaces

ASP.NET includes a range of useful classes and namespaces These class libraries can make writing Web applications easier Some of the classes

included with ASP.NET are HtmlAnchor, HtmlControl, and HtmlForm, which are included within the System.Web.UI.HtmlControls namespace

For more information on namespaces, see the online Help for the NET Framework

Server Controls

ASP.NET provides several server controls that simplify the task of creating pages These server controls encapsulate common tasks that range from displaying calendars and tables to validating user input They automatically maintain their selection state, and expose properties, methods, and events for server-side code, thereby providing a clean programming model

You will learn more about using server controls in Module 2: “Using Web Controls.”

Web Services

A Web service is an application delivered as a service that can be integrated with other Web services using Internet standards ASP.NET allows you to use and create Web services

For example, a company can assemble an online store using the Microsoft Passport service to authenticate users, a third-party personalization service to adapt Web pages to each user's preferences, a credit-card processing service, a sales tax service, package-tracking services from each shipping company, and

an in-house catalog service that connects to the company's internal inventory management applications

Web services provide the building blocks for constructing distributed based applications ASP.NET files have an aspx extension, while Web services have an asmx extension The technologies are similar; however, instead of outputting HTML, a Web service outputs a computer-readable answer to the input it receives

Web-You will learn more about Web services in Module 7: “Using Web Services.”

Trang 16

ASP.NET Features (Continued)

! Improved Security

! Greater Scalability

! Application State and Session State Management

! Easy Configuration and Deployment

Improved Security

In ASP, the only type of authentication that you can use is the Windows authentication, whereas ASP.NET allows different types of login and user authentication; Windows, Passport, and Cookies

ASP.NET also enables you to get real account impersonation and have the server execute code as if the user were present You can also programmatically check to see if the user is in a given role and conditionally let him or her perform certain tasks when given permission

In addition, creating forms-based authentication in which you can create your own custom login screen and credential checking is much easier using ASP.NET

You will learn more about authentication and creating login forms in Module 7:

“Creating an ASP.NET Web Application.”

Trang 17

ASP.NET provides a full-featured cache engine that can be utilized by pages to store and retrieve arbitrary objects across HTTP requests The ASP.NET cache

is private to each application and stores objects in memory The lifetime of the cache is equivalent to the lifetime of the application This means that when the application is restarted, the cache is recreated

You will learn more about caching in Module 7: “Creating an ASP.NET Web Application.”

Application State and Session State Management

In ASP.NET application state and session state management is extended to provide a persistent and more scalable environment for storing values relevant

to specific clients and applications In particular, a user’s session state can now easily be maintained across a Web farm because it no longer depends on client side cookies

You will learn more about maintaining state in Module 7: “Creating an ASP.NET Web Application.”

Easy Configuration and Deployment

Configuration and deployment are now easier with the use of human-readable configuration files and DLLs that don't have to be registered

In ASP.NET, all the configuration details for all Web applications are kept in human-readable files named config.web The standard format for the

configuration files is XML, and each application inherits the settings in the default config.web file

With NET, all files that a Web site needs are located under the site's root folder DLLs are in the /bin folder, and the config.web file is in the root folder

To deploy a Web site, all you have to do is copy the site’s root folder using file copy commands, the Microsoft FrontPage server extensions, or FTP

You will learn more about configuration options in Module 7: “Creating an ASP.NET Web Application.”

Trang 18

Animation: The ASP.NET Execution Model

In this animation, you will she how ASP.NET pages are processed on the

server To view the animation, open the 2063A_01A001.swf file from the Media folder

Topic Objective

To describe the ASP.NET

execution model

Lead-in

In this animation, you will

see how ASP.NET pages

are processed on the

For details on how to run

and describe the animation,

see the Multimedia

Presentation section in the

Instructor Notes for this

module

Delivery Tip

After showing the animation,

summarize the differences

between ASP and

ASP.NET

Trang 19

Demonstration: Using Visual Studio.NET

In this demonstration, you will see how to use Visual Studio.NET

In this demonstration, you

will see how Visual

Studio.NET will be used in

this course

Trang 20

Delivery Tip

1 Open Visual Studio.NET

and Create a new Web

Application project

2 Close all the windows

except the Solution

Explorer

3 Point out the files that are

added to the project by

default For most of the

course we will only be

working with ASPX files

4 An ASPX page is created

by default, WebForm1.aspx,

and is opened in Design

view Show students how to

switch to HTML view

5 A code-behind page is

created by default,

WebForm1.vb, for the ASPX

page Show students how to

delete all the attributes of

the @Page directive except

the Language attribute

Note: Even though we won't

be using the code-behind

page, it is still there Show

students how to view the

code-behind page (by

double-clicking on the ASPX

page in design view) and

how to close it (by clicking

the close button)

6 Add an HTML text control

and a button Web control to

the default form to show the

7 Add a script section to an

ASP.NET page, and create

a Click event for the button

that outputs a value in the

text box

8 Save your work

9 Either view the page in

the browser or click Start

Trang 21

# Server Controls

! What Are Server Controls?

! Types of Server Controls

! Demonstration: Adding Server Controls to an ASP.NET Page

! How Do Server Controls Work?

ASP.NET introduces the concept of server controls that encapsulate common tasks and provide a clean programming model In this section, you will learn about types of server controls and see how they work You will also learn how

to use server controls on ASP.NET pages

Topic Objective

To describe server controls

and learn how to use server

controls in your application

Trang 22

What Are Server Controls?

! Server-programmable objects

! Denoted by tag with runat=server

! Encapsulate both behavior and rendering

They provide client-specific HTML that is displayed on the client This means that you do not have to create separate pages for each browser type, nor query what type of browser is being used because the control does that for you For example, server controls can determine whether a presentation task such as making a Web page text dynamically appear or disappear should be performed

by the browser or server code If IE 4.0 or above was the destination, the code would be client side because IE 4.0 can handle dynamic text operations If an older version of IE (IE3.0) was the destination, then the code would be on the server side, resulting in a trip to the server to change the text From the user point of view the text would change, but depending on the browser type it would occur either on the client or server All this can be accomplished by a Server control, which determines the browser type and generates the appropriate code

Server controls also provide a consistent object model for the controls, providing standard properties, methods, and events

Topic Objective

To describe server controls

Lead-in

In ASP, you had to write

code for every single task

Common tasks such as

maintaining state, validating,

caching, displaying data,

and so on required several

lines of code ASP.NET

introduces server controls

that perform many of these

tasks for you

Ngày đăng: 23/10/2013, 00:15