Download Complete Programming the Web with Visual Basic NET 1st Edition Lynn Torkelson PDF for All Chapters
Download Complete Programming the Web with Visual Basic NET 1st Edition Lynn Torkelson PDF for All Chapters
com
https://ebookultra.com/download/programming-the-
web-with-visual-basic-net-1st-edition-lynn-
torkelson/
https://ebookultra.com/download/practical-database-programming-with-
visual-basic-net-second-edition-ying-baiauth/
ebookultra.com
https://ebookultra.com/download/an-introduction-to-object-oriented-
programming-with-visual-basic-net-1st-edition-dan-clark/
ebookultra.com
https://ebookultra.com/download/programming-microsoft-visual-basic-
net-version-2003-francesco-balena/
ebookultra.com
https://ebookultra.com/download/programming-microsoft-sql-
server-2000-with-microsoft-visual-basic-net-1st-edition-edition-rick-
dobson/
ebookultra.com
Programming with Microsoft Visual Basic 2012 6th Edition
Diane Zak
https://ebookultra.com/download/programming-with-microsoft-visual-
basic-2012-6th-edition-diane-zak/
ebookultra.com
https://ebookultra.com/download/windows-game-programming-with-visual-
basic-and-directx-1st-edition-freeze/
ebookultra.com
https://ebookultra.com/download/visual-c-net-programming-1st-edition-
harold-davis/
ebookultra.com
https://ebookultra.com/download/an-introduction-to-programming-using-
visual-basic-2008-with-visual-studio-expression-edition-dvd-schneider/
ebookultra.com
https://ebookultra.com/download/visual-basic-net-a-beginner-s-guide-
herbert-schildt/
ebookultra.com
Programming the Web with Visual Basic NET 1st Edition
Lynn Torkelson Digital Instant Download
Author(s): Lynn Torkelson, Constance Petersen, Zac Torkelson (auth.)
ISBN(s): 9781590590270, 1590590279
Edition: 1
File Details: PDF, 37.37 MB
Year: 2002
Language: english
Programming the Web
with Visual Basic .NET
LYNN IDRKELSON, CONSTANCE PETERSEN, AND ZAC IDRKELSON
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219,
Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, email info@apress. com, or visit
http: I IWYM. apress. com.
The information in this book is distributed on an "as is" basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
The source code for this book is available to readers at http: I !w.NJ. apress. com in the Downloads
section. You will need to answer questions pertaining to this book in order to successfully download
the code.
To Allen Ray Torkelson, father and grandfather, who taught his
family to seek out the great challenges that life offers, and who,
by example, instilled the courage to meet those challenges. And
to the memory ofHelen Lindseth Torkelson, mother and
grandmother, who taught us that making beautiful music
requires not only talent but also study and practice.
Appendix A Web Design and Usability: Tips and Tricks ........... 833
Appendix B HTML Quick Reference ........................................................ 851
Appendix C XML Quick Reference ........................................................... 863
Appendix D Setting Up Your Own Development Server ................. 875
Index ...................................................................................................................... 879
v
Contents
Foreword ............................................................................................................... xiii
vii
Contents
ix
Contents
X
Contents
xi
Foreword
Doing the Web Right
I REMEMBER MY FIRST encounter with Web development (about 2,500 years ago in
Internet time). It was an awesome experience. Suddenly it became simple to
publish my brilliant thoughts and musings for all the world to see, without resorting
to chain letters or anonymous letters to the editor. No matter that no one cared
about reading my drivel; it was enough to have it out there.
The downside to this magic was the tools necessary to make it happen. Notepad
to write code? Early Web servers that required deep magic to get set up and keep
operating? A little later, scripting code? Sheesh. The tools available at the time cer-
tainly took the luster off the whole experience. They easily set computer science
back at least fifteen years.
Later, in the middle ages of the Web, more robust tools like Microsoft's ASP and
Sun's JSP made Web application development possible and feasible. But writing or
maintaining a Web site based on ASP, with HTML interspersed with evil scripting
code, was enough to make real developers gag.
Now, early in the newest millennium, Microsoft has ushered in the new age of
the Internet with ASP. NET and VB. NET. This ain't your great grandma's Web anymore!
Web development is now possible with real programming languages and tools, real
objects in the object-oriented programming sense, and state of the art debugging
and profiling tools .. NET is just too cool, and it makes development fun again.
However, the cost of this white magic is complexity.. NET is big. Even the small
corner of .NET that directly applies to Web application development with VB.NET
is enough to present a long and difficult learning curve. Even if you have years of VB
and Web experience, you're in for some hard work just getting up to speed on these
new technologies.
That's why I was excited to learn that Constance, Lynn, and Zac were under-
taking this book. I've known Constance a long time, and she and Lynn and I have
worked together on a couple oflarge projects. They're the nicest, smartest people
I could ever hope to work with. Constance is one of the best user interface people
around, and Lynn and Zac are world-class coders. It just blows me away thatthey're
a single family. How did so much technical talent end up in one place, in one
family? (Hey, Constance and Lynn, either of you have any single sisters?)
The world is awash in .NET, VB. NET, and ASP. NET books. Do we really need
another one? My answer is a most emphatic yes when the book is conceived and
written by so talented a group of authors .. NET is a huge subject, and one of the
most impressive things about this book is that the authors have extracted and
xiii
Foreword
focused on the topics that are most important as you develop your ASP. NET Web
applications using VB. NET.
Once you understand the concepts in this book, you'll even be ready to make
sense of the more esoteric corners of .NET when your app needs specialized features.
For example, security is now an important feature of any application, all the more
so if it's on the Web where malicious hackers can bang away at it, probing for vul-
nerabilities. With this book, you'll gain an understanding of the security features of
ASP. NET for Web applications, enough to secure most apps. But, when you create
an app that requires extraordinary protection, you can build on the knowledge and
wisdom herein to achieve the system requirements. All this for less than the price
of a nice dinner!
Take this book, study its sage advice, and soak up the wisdom you'll find here.
Then get out there and take part in building the next, new generation of the Web.
And have fun doing it!
Don Kiely
Third Sector Technologies
Fairbanks, Alaska
June 2002
xiv
About the Authors
THE THREE co-AUTHORS of this book are related in both life and business. Constance
Petersen and her husband, Lynn Torkelson, are the founders of SoftMedia Artisans,
Inc. The third author is their fourteen-year-old son, Zachary Torkelson.
XV
About the Authors
xvi
Acknowledgments
THE FOLKS AT APRESS provided wonderful assistance and support throughout the
writing and production of this book. Thanks to Dan Appleman not only for encour-
aging us to take on this project and serving as editorial director, but also for writing
the Visual Basic classics that we've relied upon in the past. Thanks to Gary Cornell
and Karen Watterson for helping to get this project started on the right footing and
for making sure we covered the right topics. Even the Apress T-shirts look great!
From beginning to end, Tracy Brown, our project manager, worked closely with
us in our efforts to make sure that this book would be as valuable to the readers as
possible. Like a circus juggler, she kept many balls in the air and never let one drop.
Thanks, Tracy. It was a pleasure to work with you!
And thanks also to Scott Stab bert, technical reviewer extraordinaire. Scott not
only possesses the in-depth ASP. NET knowledge of a Microsoft insider, but his
teaching experience has shown him which aspects of this great new technology
have proved to be stumbling blocks for students. Scott's many suggestions and
explanations proved immensely valuable to us.
Heartfelt thanks to Tom Gillen whose highly skilled and good-humored editing
made the entire copyedit process fun. Tom deflated the onerous effects of our
worst cliches, cheered us on for mentioning octothorpes and singer/songwriter
James McMurtry, and, whenever we asked, patiently explained the reasons behind
his trickier edits.
Thanks to Kari Brooks, our production manager, for all the thought and care
she put into making sure our book looks great in print. Also, thanks to the dynamic
marketing duo of Stephanies-Stephanie Rodriguez and Stephanie Parker.
Stephanie Rodriguez is the marketing and public relations manager for Apress, and
she adroitly handles the marketing of our book in the Americas. Stephanie Parker is
the marketing and publicity coordinator for Springer-Verlag London limited, and, just
as adroitly, she handles the marketing of our book in Europe and the rest of the world.
We also wish to thank the many people not directly involved in the production
of this book whose dedication to software quality, performance, and usability have
informed and inspired us. Prominent in this group are Bob Arnson, Alan Cooper,
Quentin (Q) Correll, J. D. Hildebrand, Don Kiely, Deborah Kurata, Jim Kyle,
Jakob Nielsen, Sue Petersen, Karl Peterson, Dan Rogers, Jeff Russell, Bill Storage,
Zane Thomas, Kevin Weeks, and Andrew J. Wozniewicz.
And finally, thanks Nick and Daniel for your patience and support over the past
months. Let's get to know each other again this summer!
xvii
Introduction
IT'S NO SECRET that the Internet has exploded upon the scene during the past few
years. Computer applications are changing dramatically as a result. We come face
to face with the Internet almost every day, and none of us can escape noticing its
shortcomings. It's too slow. Links often take us to nowhere. Applications are infuri-
atingly obtuse. Much of the content is sheer nonsense (or worse).
And yet, we use the Internet more and more. Why? Because of the information
it holds that we can't easily get any other way. Because of the items it offers for sale
that we can't buy anywhere else. Because of the opportunity it gives us to commu-
nicate with folks all over the world who share our interests.
If we use the Internet now, under these conditions, imagine how important it is
going to be five, ten, or twenty years in the future. When a super-fast network con-
nects the world community and good Web applications routinely provide valuable
services in an intelligent way, we programmers will be able to look back on these days
with the satisfaction of those who helped to build something quite remarkable.
Many of the applications and services that we build now will still be in use far into
the future, if we build them right.
A major reason for the unsatisfactory quality of current Web applications is the
weakness of the tools that have been available to develop them. Professional
software developers steeped in the knowledge of object -oriented programming
view the sight of intermingled content and script with disgust. Many talented
developers have avoided Web development because they could not stomach the
xix
Introduction
requirement to write bad code. But, with Microsoft's release of the .NET Framework,
you no longer need to write bad code to program the Web.
In this book, we aim to demonstrate that you can use Visual Basic .NET to develop
efficient Web applications that provide a good experience for the visitor. And you can
write those Web applications using sound, object-oriented programming techniques.
XX
Introduction
will now bring their expertise to the Web. And, if you're among those unfortunate
souls who have developed (or, even worse, maintained) Web applications using
embedded script, you will truly be in a position to appreciate the new tools.
We believe that the transition to the .NET Framework will take considerable
time. Visual Basic .NET does not create COM components, and we expect many
existing Visual Basic 6 COM components to have a long lifetime. We also anticipate
that quite a few organizations will continue to use Visual Basic 6 to develop COM
components until the .NET Framework becomes pervasive. If you are like most
programmers (including us), you will be itching to experiment with Visual Basic
.NET even if your organization hasn't yet adopted it as an official programming
language. Creating your own Web site offers a perfect opportunity to get your feet
wet with Visual Basic .NET. And it's great fun!
Is this book for you? If you are an experienced Visual Basic programmer inter-
ested in programming the Web, the answer is an emphatic yes.
xxi
Introduction
About Smartisans.com
We invite you to visit our Web site, http: I lwww. smartisans. com, to see what we're up
to. Along with the archive of articles on Web design and usability, we intend to post
Web programming tips and tricks using Visual Basic .NET. Also, we will post
updates and corrections to this book. And, please, if you like our book and Web site,
tell your boss, co-workers, neighbors, friends, and family. For that matter, tell the
world-writing a book doesn't pay all that well, and our technical skills are for hire!
:xxii
CHAPTER 1
experience with a Web application lie outside of the programmer's experience, let
alone the programmer's control. The sheer number of combinations of computer
platforms, inconsistent browser versions, and network connections on the Internet
is immense. Couple this with the fact that each visitor can elect to disable scripting,
can refuse to accept cookies, and can adjust the sizes of the text that the browser dis-
plays, and you have-well-an exciting challenge. Let's just say that the Internet is
bigger and messier than the corporate world.
One of the keys to writing good, efficient Web applications is gaining a strong
working knowledge of the facilities that are available to you in the ASP. NET
namespaces. We simply can't stress this too much, and so we conclude this
chapter with a brief tour of the ASP. NET namespaces. The ASP.NET namespaces
provide a great number of useful, efficient classes already available to help you
achieve your objectives. And, where generalized facilities won't help, you can tap
into the vast store of available property information to help steer your programs
through the maze of potential problems. Throughout this book, we mine the
ASP.NET namespaces for their valuable resources. As you work through the following
chapters with us, we encourage you to do the same.
Despite the special challenges of Web programming, your hard -earned Visual
Basic .NET experience will give you a leg up in building Web applications using
ASP. NET. For example, you can still rely upon your working knowledge of multi-
tiered applications.
A quick reminder before we begin: If you aren't yet familiar with Visual Basic
.NET, read one of the other Apress books on Visual Basic .NET before you read this
book. The differences between Visual Basic 6 and Visual Basic .NET warrant a
complete volume, and we assume here that you have already learned how to
program using Visual Basic .NET. On the other hand, we don't assume that you
already know how to program Web applications-using ASP or any other technology.
And, even if you have done Web programming in the past, ASP. NET (that part of the
.NET Framework devoted to Internet programming) starts a whole new ballgame.
In this chapter and throughout this book, we assume that you use Visual
Studio .NET for your development work. You can write Visual Basic .NET programs
using Notepad, but for that matter you can dig the hole for a swimming pool with
a teaspoon. Because Visual Basic programmers generally prefer the language
because of the productivity advantages it affords, we doubt that any serious Visual
Basic .NET programmer intends to go the Notepad route.
2
Meeting the Challenges of the Web
information available to all the clients (the desktop computers) connected to the
organization's network. As technologies improved, developers created more
sophisticated applications comprising separate components that could commu-
nicate with each other over the network. Each component performed tasks that were
appropriate to the computer on which it ran. For example, components deployed
on client computers handled user interface tasks, and components deployed on
servers provided and maintained central database information.
NOTE In this book, we use tile word component in its more general sense,
rather tlzan as a synonym for COM component. However; ASP.NET Web
applications can readily employ legacy COM server components.
Business Database
Server Server
Business Database
Server Server
3
Chapter I
How does that affect your programming? To compensate for your lack of control
over the client tier, you take care to develop server components that perform
application tasks effectively regardless of the configurations used by your visitors.
Furthermore, you factor your application to allow for the redeployment of its
components to handle changes in the volume of visits. Consider the situation from
the viewpoint of the administrators of an organization's servers. Most successful
Internet applications start out with relatively light traffic that increases over time.
Once traffic approaches the capacity of the existing servers, the administrators
may add additional servers to help carry the load. They will then transfer some of
the tasks performed by the old servers to the new ones. Over time, this cycle might
be repeated many times. In fact, that's what we hope for, because it means that
we've developed a successful application. But the administrators will be able to do
their jobs effectively only if we've designed and programmed in a way that makes
this redistribution of tasks feasible. When an application or service operates effi-
ciently regardless of the amount of traffic it processes, we say that it scales well or
is scalable.
Sometimes an application acts so independently that a system administrator
can simply install it on any or all of the organization's servers. The prime example
of this is an application that reads static information from a single database and
formats it for display in the client's browser. In such cases, each incoming request
can be routed to the least-busy server by the network software.
Often, however, things aren't that simple. When customers place online orders,
for example, the underlying services cannot operate independently. What one cus-
tomer does might affect the choices available to the next customer. To create a
scalable application under these circumstances, you must break the application
into logical components that can, if necessary, be separated and executed on dif-
ferent servers. With Visual Basic 6, you do this by creating COM components and
registering them on different servers. With Visual Basic .NET, you do this by creating
and deploying assemblies using the .NET Framework. In Chapter 14, we explain
what it takes to deploy the applications you create using Visual Basic .NET. The
designers of .NET took pains to simplify this activity, as compared with the process
necessary to deploy COM components.
4
Meeting the Challenges of the Web
Whether you program for the desktop or the Web, your application's user
interface executes in the client tier. One of the major differences between desktop
applications and Web applications crops up in programming for the client tier.
Using Visual Basic .NET, you program the client tier by developing a Web form
application to interact with the Web browsers of your visitors.
5
Chapter 1
6
Meeting the Challenges of the Web
:t~ froject Build l!ebug Data FllflNt Table Jnsert Frames Iools :tllndow ttelP
.., • C'• • • Debug ~
»
u .f.
Soluuon hplorer . C. .. l X
Hello world!
Figure 1-3. This simple Web page design will display "Hello world!" in the browser.
7
Chapter 1
Hello world!
Local Intranet
Figure 1-4. The Internet Explorer browser window displays the "Hello world!" response.
8
Meeting the Challenges of the Web
You can also use your existing COM components with .NET applications. Your
Web form applications can and should make use of well-designed components
that encapsulate the business rules of your company or organization.
With the release of ASP.NET, we have a new type of component (in the generic
sense of the word) to throw into the mix. XML Web services make application-to-
application communication feasible over the Internet. Because all information that
passes to and from XML Web services is in the form of text -only XML documents (if
you aren't familiar with XML, don't worry-see the next section of this chapter), appli-
cations running on platforms other than Windows can make use ofXML Web services.
Even applications running behind firewalls can make use ofXML Web services.
The great flexibility offered by this new type of component should earn it
consideration when you decide how to partition the tasks performed within a
new application. Chapter 8 of this book is devoted to the development of XML
Web services.
The actual text in this example is "Display this as bold text." The <b> and <lb>
markup tells a browser to use a bold font to display the enclosed text. The browser
does not display the markup directly, but uses it to format the text enclosed within
the markup elements.
XML uses markup not for formatting but for describing textual content. Look
at this XML example:
9
Chapter 1
The markup in this example identifies the enclosed text as a city. Without the markup,
the text could refer to either the city or the state of New York. As a human reader,
you might be able to discern the meaning from the context, but marking up the
text in this way removes any potential ambiguities for both human readers and
computer programs.
As we mentioned earlier, Web form applications communicate with visitors by
sending HTML to client browsers. XML Web services communicate with other
applications by exchanging XML documents. XML is also used extensively within
the .NET Framework, in configuration files for example. HTML and XML share
(more or less) the same syntax, so, if you know one of them, reading the other is easy.
Let us say first that you do not have to become an expert in either HTML or
XML to develop ASP. NET applications. Second, the basics of each are quite simple,
so you won't find reading HTML or XML to be a stumbling block. Once you find
yourself writing a bit ofHTML or XML (yes, it will happen!), the IntelliSense feature
in Visual Studio .NET will come to your rescue. Soon you will feel like an old hand,
particularly at HTML.
We do not mean to suggest that you will immediately find complex HTML and
XML documents easy to read or to create from scratch. Far from it. But, when you
develop a Web application, the HTML you write (or cause to be generated) maps
directly into the controls and formatting elements that appear in the Visual Studio
.NET designer. The concrete relationship between the HTML and its visual repre-
sentation in the designer makes it easy to connect the two mentally. Similarly, the
XlVfL you write (or cause to be generated) maps directly into the data for your
project, or into some other concrete portion of your application. Again, this makes
it easy to make the mental connections.
True, the automated support for writing both HTML and XML in Visual Studio
.NET makes it possible for you to create Web applications without writing any
HTML or XML whatsoever. But, although you will usually find it convenient to let
Visual Studio .NET generate your XML, we predict that you will soon find yourself
quite comfortable working directly in the HTML window while creating your
Web pages.
NOTE In a way, the rapid feedback you get by switching between the Design
and HTML windows in Visual tudio .NET resembles the rapid feedback
fJrOIIided by tl1e interpreter for older uersions of Visual Basic. This kind of
immediate and concrete feedback boosts t11e learning rate for most people, and
doe so quite painles ly.
10
Meeting the Challenges of the Web
NOTE We regret to say that-at the time of this writing-Visual Stlldio .NET
does not generate well-formed HTML in all cases. Fortunately, because oftlze
forgiving nature ofcurrent browsers, the HTMLgenerated by Visual Sntdio .NET
does not create Web application problems at this time.
The syntactical elements that we cover here describe the vast majority of the
HTML and XML that you will encounter. In this book, we explain the few oddball
cases when they arise in programming examples. For your reference, the appen-
dices contain additional information about both HTML and XML.
The <p> in this example is the start tag for an HTML paragraph element, and the </p> is
the end tag. The text between these tags constitutes a single paragraph. The slash
identifies the latter tag as an end tag, and the name following the slash identifies
the matching start tag. We recommend that you verify that the names in the start
11
Chapter 1
and end tags match exactly, including case, to make sure that the tags are well
formed. In XML, the characters in a tag name can be any case, so long as the names
in both tags match exactly. In HTML, the latest standard (dubbed "XHTML")
requires lowercase tag names.
Elements can be (and usually are) nested, and often they are deeply nested.
Look at this example of nesting, this time in XML:
<Address>
<Street>7767 Guinevere Way</Street>
<City>Atlanta</City>
<State>Georgia</State>
<Zip>30345</Zip>
<Country></Country>
</Address>
The address element in this XML example encompasses five nested elements. The
start and end tags clearly reveal the structure of the data. Although most elements
enclose content, they aren't required to do so. The Country element in this example
is perfectly acceptable. For either HTML or XML to be well formed, each child element
must be completely contained within its parent. That is, tags must not overlap.
We told you this was easy! Let's expand our horizons a bit.
<p id="preamble">
In times like these, the need for improvement has never been more clear.
Let us consider the ways in which improvements might be made.
<lp>
This HTML paragraph is not just any old paragraph. It is the particular paragraph
with an id attribute of "preamble". We give this example because, to program
against any HTML element using Visual Basic .NET, that HTML element must have
a unique ID attribute. When you think about it, the requirement makes sense.
Take another look at the preamble paragraph. Unlike the earlier examples, the
text content of the preamble paragraph is not jammed right up against the tags.
That does not matter-all of the so-called whitespace before and after the content
is condensed into a single space when it is displayed in a browser.
12
Meeting the Challenges of the Web
Now we can introduce the next wrinkle. It is possible for an element to have
only attributes and no content. Check out the following HTML:
This HTML element defines a text box used to capture data entered by the visitor.
Because this element never encloses content, the element does not need the nor-
mal end tag, and browsers today do not require one. Instead, the ending slash can
(and should!) appear just before the closing angle bracket. Such elements are called
empty tags or leaf nodes. Empty HTML tags, including the <br I> (line break) tag,
should contain a space before the slash to ensure correct parsing by older browsers.
13
Chapter 1
Note that the value attribute is enclosed in single quotes. This substitution avoids
the conflict that would otherwise arise because of the double quotes to be displayed
in the HTML text box.
Sometimes you want to insert a space in an HTML document that will
not be condensed into the whitespace. In such cases, use the nonbreaking
space reference: .
<html>
<head>
<title>HTML Sample</title>
</head>
<body>
<p>
This is a paragraph in an HTML document.
<lp>
</body>
</html>
Because current browsers accept HTML that is not well formed, you will definitely
encounter HTML that doesn't adhere to the syntax rules spelled out here. The most
common offenders are empty elements with no end tags.
When you develop Web form applications, you will often want to look at the
HTML that's actually received by the browser from your application. You can view
the HTML from Internet Explorer by choosing View~ Source. Figure 1-5 shows the
HTML sent to the browser from our Hello World application. Note that Visual
Studio .NET itself did not generate well-formed HTML when it created the META
tags. (Don't tell anybody, but, while visiting a Web site that looks remarkable in one
way or another, we often peek at its HTML.)
In Chapter 4, we describe the most common HTML tags in connection with
their use as HTML controls. Appendix B of this book is a quick reference that con-
tains more information about the structure and use ofHTML.
14
Meeting the Challenges of the Web
Figure 1-5. The browser spills the beans about the HTML it is displaying.
15
Chapter 1
interfaces provides the data source independence that is needed for true interop-
erability. As shown in the example in Figure 1-6, an XML document can be read by
both humans and computers and has a striking resemblance to HTML. However,
an XML document describes the content of the information within it, rather than
the format for its display. All XML documents must be well formed.
Figure 1-6. Each pair of XML tags in an XML document describes the information
contained between the tags.
The screenshot in Figure 1-6 shows the top portion of an XML document
displayed in Internet Explorer with no additional formatting applied. Note that
Internet Explorer marks the start tag of each nested element with a minus sign(-)
or plus sign (+) to collapse or expand its display.
Every XML document.contains two sections: the pro log and the content. The
first section is the prolog, which, at a minimum, identifies the document as being
an XML document. The XML declaration in Figure 1-6 is the entire prolog:
c?xml version="l.O"?>
16
Meeting the Challenges of the Web
Other prolog lines may be present in XML documents, but the XML declaration
containing the version number attribute is the only line that's required. The prolog
of an XML document ends when the content portion of the document begins. The
content portion consists of elements delimited by start tags and end tags. We call
the first element in the document the root element. The root element in Figure 1-6
is the Albums element. The content portion of the example XML document begins
with the Albums start tag, as shown here:
<Albums Count="2">
Just as you find it useful to include comments in your Visual Basic code, you'll
sometimes see comments in XML and HTML documents. The fourth line in Figure
1-6 shows the format of a comment statement:
Comments begin with<!-- and end with-->. Comments cannot appear anywhere
within tags, but, aside from that limitation, XML allows a great deal of flexibility in
using them. You can put comments in the prolog, after the XML document, or
within the textual portions of the document. The only restriction placed upon the
text within a comment is the understandable prohibition on the use of--> within
a comment. Therefore, you can comment out portions of an XML document that
you are testing in much the same way as you can comment out portions of your
Visual Basic code.
The entire content of the example document is enclosed within the Albums
start tag and the associated end tag. The actual end tag (not shown in Figure 1-6),
the last line of the document, looks like this:
</Albums>
Because the root element actually defines the overall document, it is also known as
the document element. The elements nested within the root element flesh out the
details of the document content. For more information about XML, see Appendix C.
17
Chapter I
speed. Over time, the costs of computer hardware dropped greatly, and spending
valuable programmer time to squeeze out the last drop of performance could not
be justified. Few managers questioned spending money to reduce online response
time from ten seconds to one second, but almost every manager questioned
spending money to reduce response time from 1/10 of a second to 1/100 of a
second. In Web programming, however, response time has again become a major
consideration. So has the efficient use of network and computer resources. These
factors influence both the design and the implementation of Web applications.
Every Web session comprises a series of round trips between the client and
server. As Figure 1-7 illustrates, the first round trip in the session starts when the
visitor requests a particular URL from his or her browser. The first round trip ends
when the requested Web page appears in the client's browser. Once the session has
been established, each subsequent round trip begins with an action at the client
that (typically) requests information from, or provides information to, the server.
The server processes the request or information, and then it responds to the client.
URL
HTML Page
1.
Link
Another HTML Page
2.
Text In ut
3.
Figure 1-7. When using the Web, each round trip begins with an action at the client
and ends with a response from the server.
18
Meeting the Challenges of the Web
When you develop a Web application, your code runs on the server-but the
visitor occupies the driver's seat. The visitor controls the length of the application
session and the sequence of pages displayed within the session. He or she can
abandon the session at any time, leaving it up to ASP.NET to conclude the session
after the time-out interval elapses. The Web application, on the other hand, treats
each request as an independent unit, forgetting everything about the requests that
have come before. This intentional forgetfulness constitutes stateless execution, a
technique that conserves server resources and improves scalability. If the client
abandons the session, no application resources are tied up waiting futilely for the
next client action.
Let us hasten to add, however, that stateless execution does not mean that
your Web application lacks the means to find its place in a back-and-forth exchange
with the client. Indeed, ASP. NET knows about your application and about your
session with the client. It uses very efficient techniques for keeping track of the
traffic on the server and for storing the small amount of information that is needed
to maintain continuity within sessions. By making use of the facilities provided by
ASP.NET, you can write scalable Web applications that do not appear in the least
forgetful to the visitors. One of the sections in Chapter 2 describes the ASP. NET
facilities you can use to store state information efficiently even though your Web
form instance is destroyed after sending a response to the visitor.
19
Chapter 1
Done Locallntr~et
Figure 1-8. The initial presentation contains text that marks the positions of the two
labels on the Web page.
End Sub
20
Meeting the Challenges of the Web
#End Region
End Class
We have used traditional-looking Visual Basic names for the controls on the Web
form: txtinput for the textbox used to accept visitor input, lbl Top for the first label
underneath the buttons, and lblBtm for the second label under the buttons. You
may have noticed, however, that Listing 1-1 makes no reference to the two buttons
whatsoever. As you will soon see, we have no need to reference either button in
this project.
First, however, let's step through what happened in the code when the visitor
first requested the Web form. (In this case, of course, we simulated that request by
starting the application from Visual Studio .NET.) The first time the visitor brings
up the Web form, the IsPostBack property is False. This gives you a chance to
perform any initial processing that your Web form requires. On subsequent Load
events, ASP.NET sets the IsPostBack property to true. In Listing 1-1, therefore, the
following statements execute during the initial load:
21
Chapter 1
and then:
We discuss the InnerHtml and Value properties in Chapter 4. As you can see from
Figure 1-8, however, these statements initialize the Web form.
If you are following along with this on your own computer, enter some text in
the textbox at the top of the page. Now click the Reset button and watch the text
disappear. (If you are not following along on your computer, you'll have to take our
word for this.) What has happened is that the browser itself understands the
function of an HTML Reset button and has restored the contents of the textbox to
its original value-which, in this case, is an empty string. Now enter some more
data, as we have done in Figure 1-9.
Reset 1 I Subm~ I
Original top label text
Figure 1-9. The visitor has entered "Visual Basic .NET" into the textbox in preparation
for clicking the Submit button.
22
Meeting the Challenges of the Web
This time, click the Submit button. The browser recognizes this as a signal that
the visitor is ready to post back some data to the server. Now, when the Web form's
Load event fires, the IsPostBack property is true. Therefore the following statements
execute:
and then:
The text of the top label is moved to the bottom label, and the text entered by the
visitor is moved to the top label. That finishes our processing at the server, so
ASP. NET sends the updated form back to the client, completing the second round
trip in the session. Figure 1-l 0 reveals that the Web form now displays exactly
those changes.
Reset J . Submit ]
LocallntrOillet
Figure 1-10. The text entered by the visitor has moved to the top label, and the
original text from the top label has moved down a notch.
23
Chapter 1
Remember how clicking the Reset button earlier erased the text you entered at
the browser? Now you can tell that the Reset command did not trigger a postback
to the server. If it had, the code in the Page_ Load event handler would have moved
the text you entered into the top label.
But wait a minute! What about stateless execution? If the second round trip
built the Web form again from scratch, where did the text in the top label come from
to be moved to the bottom label? How could the following statement work at all?
Me.lblBtm.InnerHtml = Me.lblTop.InnerHtml
The answer is that ASP. NET worked behind the scenes to restore the text of the
labels before it fired the Load event. And where did ASP. NET get those values? From
a hidden field in the HTML that was returned with the new request from the client.
ASP. NET put the hidden field into the HTML just before it sent the HTML to the
client in response to the original request. If you look at Figure 1-11, you'll see the
following code in the source HTML at the browser:
By default, ASP.NET avoids the need to save state information at the server by
transmitting that information in an encoded form to the client for storage there.
Before firing the Load event after a postback, ASP.NET restores the original values of
the fields that were not changed at the client. Needless to say, using network
resources in this way is not always the right way to go, and we reexamine this topic
in Chapter 2.
It would certainly be better if you could use your desktop techniques in Web
applications. In Chapter 6, as a matter of fact, we do show how to perform simple
client-side validation checks using JavaScript. (Don't worry-ASP.NET supplies the
script.) Realistically, however, many validation checks require information held by
servers. Someday, perhaps, you'll be free of the constraints that force you to con-
sider factors other than the visitor's experience when you develop Web applications.
For now, though, you must program to minimize the impact of the Internet's
limitations upon your visitors.
24
Meeting the Challenges of the Web
Reducing Traffic
When you program a desktop application, you often give your user instant feedback.
If he or she makes an invalid entry in a form field, for example, you immediately
display any information that the user needs to correct that entry. Doing so allows
the user to make the correction before he or she starts a new train of thought. From
a good, object -oriented programming perspective, the property receiving the
value makes the determination whether or not that value adheres to the validation
rules for the property.
25
Chapter 1
If you've made online purchases, you know from personal experience that
most Internet applications work differently. On the Web, you fill out a form requiring
your name, address, credit card information, phone number, and email address
before you click on the button to submit your information. After checking your
entries in one little batch, the Web application lets you know about any errors you
may have made or, if you've entered everything right, sends you a positive confir-
mation. This technique reduces the number of round trips needed between the
client and server, which is an important goal in Internet programming. Because of
the overhead required to route and validate messages exchanged between computers,
each round trip (ideally) carries a substantial amount of information. Not only
does this technique make efficient use of network resources, it also improves the
visitor's overall experience with the application-at least when compared with ini-
tiating a round trip to the server after each field entry.
26
Other documents randomly have
different content
through hatred, and in order that he whom he attempted to accuse
might suffer death, or bodily injury, or the loss of his property; he
shall be delivered over into the power of him he accused, that he
may himself suffer the penalty which he endeavored to inflict upon
an innocent person.
Where anyone states that he is in the possession of any fact
which should be brought to the notice of the king, and should be, at
the time, in the place where the court was sojourning, he shall
straightway reveal all that he knows, or shall communicate it to the
ears of the king through the agency of some reliable person. If,
however, at the time, the king should be at a distance, and the said
party should believe that information in his possession relating to the
accusation of another, ought to be sent to the king by the hands of a
messenger, he must draw up a letter, and in it set forth plainly what
he wishes to say concerning the alleged guilt of the accused; and he
must do this in the presence of him whom he has selected to convey
the information to the king. And, in order that he may not be able to
deny the aforesaid communication, three witnesses, known to be
men of respectable character, must, in the presence of one another,
affix their seals or signatures to said letter.
FLAVIUS CHINTASVINTUS KING.
VI. How Kings should Practice the Duties of Mercy.
Whenever a supplication is made to us on behalf of those who
have been implicated in any crime against our majesty, we willingly
give attention to such appeals, and exercise the prerogative of mercy
when it is consistent with our power. We must, however, refuse to
interfere when a crime of this kind has been committed against the
nation and our country. Yet, if a prince should desire to be merciful to
persons of such wicked character, he shall have the right to do so,
with the approval of the ecclesiastics and the principal officers of the
court.
ANCIENT LAW.
I. Concerning Those who Administer Drugs for the
Production of Abortion.
If anyone should administer a potion to a pregnant woman to
produce abortion, and the child should die in consequence, the
woman who took such a potion, if she is a slave, shall receive two
hundred lashes, and if she is freeborn, she shall lose her rank, and
shall be given as a slave to whomever we may select.
ANCIENT LAW.
II. Where a Freeborn Man Causes a Freeborn Woman to
Abort.
If anyone should cause a freeborn woman to abort by a blow, or
by any other means, and she should die from the injury, he shall be
punished for homicide. But if only an abortion should be produced in
consequence, and the woman should be in no wise injured; where a
freeman is known to have committed this act upon a freewoman, and
the child should be fully formed, he shall pay two hundred solidi;
otherwise, he shall pay a hundred solidi, by way of satisfaction.
ANCIENT LAW.
III. Where a Freeborn Woman Causes another Freeborn
Woman to Abort.
Where a freeborn woman, either by violence or by any other
means, causes another freeborn woman to abort, whether, or not,
she should be seriously injured as a result of said act, she shall
undergo the same penalty provided in the cases of freeborn men.
ANCIENT LAW.
IV. Where a Freeborn Man Produces Abortion upon a Slave.
Where a freeborn man produces abortion upon a female slave,
he shall be compelled to pay twenty solidi to the master of the slave.
ANCIENT LAW.
V. Where a Slave Produces Abortion upon a Freeborn
Woman.
Where a slave produces abortion upon a freeborn woman, he
shall receive two hundred lashes in public, and shall be delivered up
as a slave to said woman.
ANCIENT LAW.
VI. Where a Slave Produces Abortion upon a Female Slave.
Where a male slave produces abortion upon a female slave, he
shall be compelled to pay ten solidi to her master, and, in addition,
shall receive two hundred lashes.
FLAVIUS CHINTASVINTUS, KING.
VII. Concerning Those who Kill their Children before, or after,
they are Born.
No depravity is greater than that which characterizes those who,
unmindful of their parental duties, wilfully deprive their children of life;
and, as this crime is said to be increasing throughout the provinces
of our kingdom and as men as well as women are said to be guilty of
it; therefore, by way of correcting such license, we hereby decree
that if either a freewoman or a slave should kill her child before, or
after its birth; or should take any potion for the purpose of producing
abortion; or should use any other means of putting an end to the life
of her child; the judge of the province or district, as soon as he is
advised of the fact, shall at once condemn the author of the crime to
execution in public; or, should he desire to spare her life, he shall at
once cause her eyesight to be completely destroyed; and if it should
be proved that her husband either ordered, or permitted the
commission of this crime, he shall suffer the same penalty.[35]
TITLE IV. CONCERNING INJURIES, WOUNDS, AND MUTILATIONS INFLICTED
UPON MEN.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com