Contents
Overview 1
Introducing ASP.NET 2
Server Controls 13
Adding ASP.NET Code to a Page 23
Handling Page Events 30
Lab 1: Using ASP.NET to Output Text 35
Review 36
Module 1: Working with
ASP.NET
BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY
Information in this document is subject to change without notice. The names of companies,
products, people, characters, and/or data mentioned herein are fictitious and are in no way intended
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
!
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)
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">
End Sub
3. View the page in Internet Explorer. The text box gets loaded with default
text each time.
4. In the Page_Load event procedure, check for IsPostBack and only initialize
the text box the first time the page is loaded.
If Not Page.IsPostBack Then
txtName.Value = "Enter your name"
End If
5. View the page again. Now the initial text is only used the first time.
vi Module 1: Working with ASP.NET
BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY
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:
Action Say this
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
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.
ASP ASP.NET
.asp files .aspx files
Can only be scripted using VBScript or
JScript
Language independent
Difficult to reuse code Allows separation of code and content
Need to write code for everything Provides server controls
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
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.
Topic Objective
To provide an overview of
the module topics and
included in the section.
Lead-in
Before you start using
ASP.NET, you should have
an overview of ASP.NET
and its framework.
Module 1: Working with ASP.NET 3
BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY
The .NET Framework
Base Class Library
Data
Win Forms
Common Language Runtime
Web Forms
Web ServicesThe .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
operating system. ASP.NET
is a part of the .NET
Framework that supports all
applications in Windows.
4 Module 1: Working with ASP.NET
BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY
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
WinForms will not be covered as part of this class.
6 Module 1: Working with ASP.NET
BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY
ASP.NET Features
!
Multiple Language Support
!
Increased Performance
!
Classes and Namespaces
!
Server Controls
!
Web ServicesASP.NET is more than just the next version of ASP. It is a totally rearchitected
technology for creating dynamic, Web-based applications. While ASP pages
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.
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 Web-
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.
You will learn more about Web services in Module 7: “Using Web Services.”
8 Module 1: Working with ASP.NET
Caching is an extremely important technique for building high-performance,
scalable Web server applications.
ASP.NET offers two caching mechanisms; output caching and ASP.NET
caching that enhance Web application performance.
Output caching is a powerful technique that increases server application
throughput by caching the content generated from dynamic pages. The output
cache is enabled by default and will cache any response that has a valid
expiration or validation policy, and public cache visibility.
Module 1: Working with ASP.NET 9
BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY
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.”
Greater Scalability
Scalability of .NET applications is enhanced because pages are compiled, and
page output can be cached.
In addition, using ASP.NET, session state can now be maintained in a separate
process on a separate machine, or in a database allowing for cross server
sessions. This allows you to add more Web servers as your traffic grows.
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