Validation Controls
One common task when working with HTML forms in a Web application is the validation
of values that the user enters. They may have to fall within a prescribed range,
be non-empty, or even have the values from several controls cross-referenced
to check that the inputs are valid.
Traditionally, this has been done using either client-side or server-side scripts,
often specially written for each form page. In ASP+, a range of Validation Controls is included. These make it easy to perform
validation checks – both client-side and server-side.
Five types of validation control are provided. The RequiredFieldValidator
control, CompareValidator control, RangeValidator control,
and RegularExpressionValidator
control perform various types of checks to ensure that that a control contains
a specific value, or matches the value in another control. The CustomValidator control
passes the value that a user enters into a control to a specified client-side
or server-side function for custom validation. The ValidationSummary
control collects all the validation errors and places them in a list within
the page.
Each one of these controls (except the ValidationSummary
control) is linked to one or more HTML controls through the attributes you set
for the validation control. They can automatically output the text or character
string you specify when the validation fails. You can also use the IsValid
method of the Page
object to see if any of the validation controls
detected an error, and provide custom error messages.
Some of the controls also detect the browser type, and can output code that
performs validation client-side without requiring a round-trip to the server.
If this is not possible, code to do the validation during the submission of
the values to the server is output instead. We look in detail at how we can
use these controls in Chapter 4.
You'll see most of the controls we've discussed described in more detail in
Chapter 2. The more complex
topics associated with them, such as templates, server-side data binding and
ADO+ are covered in Chapter 3. Chapter 4 looks at the validation controls, and other
advanced techniques in ASP+ pages. We also look at how you can build your own
custom server-side controls in Chapter 7.
ASP+ Web Services
As the march of XML through traditional computing territory continues unabated,
more and more of the ways that we are used to doing things are changing. One
area is the provision of programmatic services that can be consumed by remote
clients, especially where the server and client are running on different operating
system platforms. The Simple Object Access Protocol
(SOAP) is an XML grammar that allows clients to take advantage of the services
provided by a remote server or application, by providing the requests in a standard
format.
ASP+ includes support for the creation of suitable server or application objects
that accept SOAP requests, and return the results in SOAP format. The technology
is called Web Services, and allows developers to
create these objects quickly and easily within the .NET framework.
These objects are also automatically discoverable and described to clients
using the XML-based Service Description Language
(SDL).
You simply create the object using normal server-side code as a public
class,
in any of the supported languages, and include one or more methods that the
client can access marked with the special [Web Method]
indicator. These are known as custom attributes. Other methods that are not
marked as such are not exposed, and cannot be accessed by clients. No knowledge
of COM+ or HTTP itself is required, and the source for these service objects
is just text files.
Web Services allows custom business service objects to be created quickly and
easily by ASP+ developers. The client can access them synchronously or asynchronously,
using the HTTP-GET, HTTP-POST
or HTTP-SOAP
methods that provide extra flexibility. As with other objects in ASP+, the source
is compiled, cached and executed under the
runtime. We explore the whole concept of Web Services in Chapter 5.
ASP+ Configuration and Deployment
In earlier versions of ASP, a file named global.asa
could exist in the root directory of a virtual application. This file defined
global variables and event handlers for the application. However, all other
configuration details for the entire Web site were made in the Internet Services Manager
snap-in to the MMC. The settings made in Internet Services Manager are stored in the
IIS metabase, which is a server-based machine-readable file that specifies the
whole structure of the Web services for that machine.
This has at least one major disadvantage. It requires the administrator or
developer to access the metabase using either
Internet Services Manager (it can be used remotely to access another
machine on the LAN), the equivalent HTML pages, or custom pages that access
the metabase through the Active Directory Services Interface (ADSI).