Validate User Input

Problem

You want to examine controls for invalid input before continuing.

Solution

Use one of the five validator controls included with ASP.NET.

Discussion

Web applications are frequently subject to input errors because all the information is entered on the client side. Unlike in Windows applications, you can’t rely on events such as KeyPress to check input as it is entered. The only way to remedy these problems is to add your own JavaScript code for this purpose (as described in recipe Use JavaScript to Handle Key Presses, Mouse Movements, and More) or use the validator controls.

The validator controls serve two purposes: they check control values for input errors, and they display messages describing these errors. In addition, ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.