Uh-oh, it looks like your Internet Explorer is out of date.

For a better shopping experience, please upgrade now.

ASP.Net in 60 Minutes a Day

ASP.Net in 60 Minutes a Day

by Glenn Johnson

  • Introduces Microsoft's widely-used, free Web development tool to new users and to those preparing for certification
  • Includes thirty one-hour lessons that recreate a typical week-long introductory seminar
  • Gets readers quickly up-to-speed on using ASP.NET and Web Matrix to develop Web pages and Web services
  • The author has taught


  • Introduces Microsoft's widely-used, free Web development tool to new users and to those preparing for certification
  • Includes thirty one-hour lessons that recreate a typical week-long introductory seminar
  • Gets readers quickly up-to-speed on using ASP.NET and Web Matrix to develop Web pages and Web services
  • The author has taught ASP.NET and other Microsoft tools for Xerox Connect and other major corporations
  • Companion Web site features an online presentation by the author that follows along with each chapter and includes an audio-only option for readers with dial-up Internet connection

Product Details

Publication date:
Gearhead Press Series , #28
Product dimensions:
7.41(w) x 9.19(h) x 1.78(d)

Related Subjects

Read an Excerpt

ASP.NET in 60 Minutes a Day

By Glenn Johnson

John Wiley & Sons

Copyright © 2003

Glenn Johnson
All right reserved.

ISBN: 0-471-43023-4

Chapter One

Exploring ASP.NET
and Web Forms

The last chapter covered the setup and configuration of the development environment.
The development environment is an important necessity and will
make the rest of your development more enjoyable.

This chapter explores Web Forms. Web Forms bring the structure and fun
back to Web development. This chapter starts by looking at the two programming
models for ASP.NET. It then looks at how ASP.NET uses server controls
and at the HTML (HyperText Markup Language) and Web server controls. It
finishes by looking at view state and post back.

Web Forms

Web Forms are an exciting part of the ASP.NET platform. Web Forms give the
developer the ability to drag and drop ASP.NET server controls onto the form
and easily program the events that are raised by the control. Web Forms have
the following benefits:

Rendering. Web Forms are automatically rendered in any browser. In
addition, Web Forms can be tweaked to work on a specific browser to
take advantage of its features.

Programming. Web Forms canbe programmed using any .NET language,
and Win32 API calls can be made directly from ASP.NET code.

.NET Framework. Web Forms are part of the .NET Framework, therefore
Web Forms provide the benefits of the .NET Framework, such as performance,
inheritance, type safety, structured error handling, automatic
garbage collection, and xcopy deployment.

Extensibility. User controls, mobile controls, and other third-party controls
can be added to extend Web Forms.

WYSIWYG. Visual Studio .NET provides the WYSIWYG (what you see
is what you get) editor for creating Web Forms by dragging and dropping
controls onto the Web Form.

Code Separation. Web Forms provide a code-behind page to allow the
separation of HTML content from program code.

State Management. Provides the ability to maintain the view state of
controls across Web calls.

Classroom Q & A

Q: I am currently developing my entire Web page by typing the HTML
and client-side script into an ASCII editor. Are standard HTML tags
with client-side script still available? Also, can I still use JavaScript
for client-side code?

A: Yes. ASP.NET is focused around the added functionality of server
controls, but you can still use standard HTML tags with client-side
script as you have done in the past. As you become more familiar
with the Visual Studio .NET environment, you may choose to
change some of your controls to server controls to take advantage
of the benefits that server controls provide.

Q: Can I use ASP and ASP.NET pages on the same Web site? Can I use
Session and Application variables to share data between the ASP
and ASP.NET pages?

A: Yes and no. You can run ASP and ASP.NET Web pages on the same
Web site; in order words, the pages can coexist. You cannot share
application and session data between the ASP and ASP.NET pages,
because the ASP and ASP.NET run under separate contexts. What
you will find is that you will have one set of Session and Application
variables for the ASP pages and a different set of Session and
Application variables for the ASP.NET pages.

Q: It's my understanding that there are two types of server controls.
Can both types of server controls be used on the same Web page?

A: Yes. Visual Studio .NET provides HTML and Web server controls.
You can provide a mixture of these controls on the same page.
These controls will be covered in this chapter.

Q: I currently use VBScript and JavaScript to write my server-side
code. Basically, if I am writing the ASP page and a function is easier
to accomplish in JavaScript, I write it in JavaScript. For all other
programming, on the page, I use VBScript. Can I continue to mix
Visual Basic .NET and JavaScript on the same page?

A: No. ASP.NET requires server-side script to be written in the same
language on a page-by-page basis. In addition, Visual Studio .NET
requires a project to be written in a single server-side language.

Two ASP.NET Programming Models

People who are familiar with traditional ASP are accustomed to creating a single
file for each Web page. ASP.NET supports the single-file programming model.
Using the single-page programming model, the server code and the client-side
tags and code are placed in the same file with an .aspx file extension. This
doesn't do anything to help clean up spaghetti code, but the single-file model
can be especially useful to ease the pain of migrating ASP code to ASP.NET.

The two-page model provides a separation of the server-side code and
client-side HTML and code. The model offers the ability to use an .aspx page
for the client-side presentation logic and a Visual Basic code-behind file with a
.vb file extension for the server-side code.

This chapter starts by using the single-page model due to its simplicity.
After most of the basic concepts are covered, the chapter switches to the two-page
model. The two-page, or code-behind, model is used exclusively
throughout the balance of the book due to the benefits it provides.

Simple ASP.NET Page

Using the single-page programming model, a simple Hello World page using
ASP.NET can be written and saved to a file called vb.aspx containing the

<%@ Page Language="vb" %>

Hello World Web Page

Hello World

The first line of code contains the page directive, which contains the compiler
language attribute. The compiler language attribute can only be used
once on a page. If additional language attributes are on the page, they are
ignored. Some language identifiers are shown in Table 3.1. If no language
identifier is specified, the default is vb. The page directive has many other
attributes, which will be covered throughout this book.

The language identifiers that are configured on your machine may be
found by looking in the machine.config file, which is located in the
%systemroot%\\Microsoft.NET\Framework\version\CONFIG folder. The
machine.config file is an xml configuration file, which contains settings
that are global to your machine. A search for compilers will expose all of
the language identifiers that are configured on your computer. Always
back up the machine.config file before making changes, as this file affects
all .NET applications on the machine.

The rest of the page looks like standard HTML, except that this page contains
three server controls: the form, the asp:TextBox, and the asp:Button.
Server controls have the run="server" attribute. Server controls automatically
maintain client-entered values across round trips to the server. ASP.NET automatically
takes care of the code that is necessary to maintain state by placing
the client-entered value in an attribute. In some cases, no acceptable attribute
is available to hold the client-entered values. In those situations, the client-entered
values are placed into a input type="hidden" tag.

When the page is displayed in the browser, the text box displays the initial
Hello World message. A look at the client-side source reveals the following:

Hello World Web Page

<input type="hidden"
<input type="text"
value="Hello World" id="Hi" />
<input type="submit"
value="Say Hi" id="Button1" />

The form server control was rendered as a standard HTML form tag with
the action (the location that the data is posted to) set to the current page. Anew
control has been added automatically, called the __VIEWSTATE control. (More
on the __VIEWSTATE control is provided in this chapter.) The asp:TextBox
Web server control was rendered as an HTML text box and has its value set to
"Hello World." The asp:button Web server control was rendered as an HTML
Submit button.

If Hi Universe is typed into the text box and the button is clicked, the button
will submit the form data to the server and return a response. The response
simply redisplays the page, but Hi Universe is still in the text box, thereby
maintaining the state of the text box automatically.

A glimpse at the client-side source reveals the following:

Hello World Web Page

<input type="hidden"
<input type="text"
value="Hi Universe" id="Hi" />
<input type="submit"
value="Say Hi" id="Button1" />

The only change is that the text box now has a value of Hi Universe. With traditional
ASP, additional code was required to get this functionality that is built
into ASP.NET server controls.

Many changes have been made in the transition from ASP to ASP.NET. Table
3.2 shows server tags that are either new or have a different meaning in
ASP.NET. Understanding these changes will make an ASP to ASP.NET migration
more palatable.

Server Controls

A server control is a control that is programmable by writing server-side
code. Server controls automatically maintain their state between calls to the
server. Server controls can be easily identified by their runat="server" attribute.
A server control must have an ID attribute to be referenced in code. ASP.NET
provides two types of server controls; HTML and Web. This section looks at
these controls.

HTML Server Controls

HTML server controls resemble the traditional HTML controls, except they
have a runat="server" attribute. There is typically a one-to-one mapping of an
HTML server control and the HTML tag that it renders. HTML server controls
are primarily used when migrating older ASP pages to ASP.NET. For example,
the following ASP page needs to be converted to ASP.NET:

Employee Page

<input type="text"
id=" EmployeeName " >
<input type="submit"
value="Submit" id=" SubmitButton" >

This sample page can be converted by adding the runat="server" attribute to
the form and input tags, and removing the action="vb.asp" attribute on the
form. The filename needs an .aspx extension. The modified Web page looks
like this:

Employee Page

<form name="Form1" method="post" id="Form1" runat="server">
<input type="text"
id="EmployeeName" runat="server" >
<input type="submit"
value="Submit" id="SubmitButton" runat="server">

This example shows how the use of HTML controls can ease a conversion
process. If the existing tags had JavaScript events attached, those client-side
events would continue to operate.

This ease of migration benefit can also be a drawback. Being HTML-centric,
the object model for these controls is not consistent with other .NET controls.
This is where Web server controls provide value.

Web Server Controls

Web server controls offer more functionality than HTML controls, their object
model is more consistent, and more elaborate controls are available. Web
server controls are designed to provide an object model that is heavily focused
on the purpose of the object rather that the HTML that is generated. In fact, the
Web server control's source code will typically be substantially different from
the HTML it generates. Some Web server controls, such as the Calendar and
DataGrid, produce complex tables with JavaScript client-side code.

Web server controls have the ability to detect the browser capabilities and
generate HTML that uses the browser to its fullest potential.

During design, a typical Web server control's source code will look like the

The attributes of the Web server control are properties of that control, and
may or may not be attributes in the generated HTML.

Server Control Recommendations

Consider using HTML server controls when:

* Migrating existing ASP pages to ASP.NET.

* The control needs to have custom client-side script attached to the
control's events.

* The Web page requires a great amount of client-side code, where
client-side events need to be programmed extensively.

In all other situations, it's preferable to use Web server controls.

Server Control Event Programming

An important feature of server controls is the ability to write code that executes
at the server in response to an event from the control.


When a Web Form is rendered to the browser, a hidden HTML input tag is
dynamically created, called __VIEWSTATE (ViewState). This input contains
base64-encoded data that can be used by any object that inherits from
System.Web.UI.Control, which represents all of the Web controls and the
Web Page object itself.


Excerpted from ASP.NET in 60 Minutes a Day
by Glenn Johnson
Copyright © 2003 by Glenn Johnson.
Excerpted by permission.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.

Meet the Author

GLENN JOHNSON is a professional trainer whose experience spans the years from COBOL and assembly language to Novell and Microsoft .NET. Formerly the Director of Information Technologies and Technical Support for Tyco International, Johnson now runs his own training business. He has developed courseware for and taught classes on ASP.NET, Visual Basic .NET, C#, and .NET internals.

Customer Reviews

Average Review:

Post to your social network


Most Helpful Customer Reviews

See all customer reviews