Performing Validations with asp.net - Part 1

xiaoxiao2021-03-06  53

Imagine a user visits your site. Imagine also that your site sells books. The user first screens the available books on the site. While screening, they fill out a form, which would enable them to provide quantity details, address and other relevant information. Suppose, however, that your user submits the form without filling in the zip code. After submitting the form, the server returns an error indicating null field provided there is no proper error handling techniques employed on the server side script. It is here that the usage of validations should come into picture. Validation means checking for accuracy and correctness of the entered data. By employing proper validations, you not only check for the above-mentioned criteria but also can prompt a user to enter a correct value and thereby avoid costly Errors. THESEERRORS CAN Be Either Due To Carelessness of Users or Due To Some Other Reason.if You Are Not Employing Validations, Then If The Server Returns An Error, IT May BE Unreco gnizable for a user. This could tempt the user to leave your site. You could be losing an order and a valuable customer. These difficulties can be avoided if the form had been properly validated. During development, proper rules must be set to let the user know what to do if a specified error occurs. The form should have to be validated in such a way that the user should compulsorily enter data without which, the data can not be submitted to the database on the server. You can also employ a system WHEREBY YOUR USER COULD ENTER DATA IN A Required Format Such as Only 5 Digits for A Zip Code OR A Phone Number In (- --- Format.

There are two types of validations like client-side and server-side. While client side validations can be performed using JavaScript and VBScript, server side validations can be achieved via classic ASP. The biggest problem with these languages ​​and technologies is that you have to write lengthy code to perform a simple task. Since, VBScript will not work with Netscape browser, you can not perform client-side validations using this language. you have to learn JavaScript or Classic ASP to perform validations. with ASP.NET, these difficulties are eliminated. ASP.NET provides its own built-in controls for validations. You can easily place controls and write codes by using a text editor like Notepad or an IDE like Visual Studio .NET. moreover, ASP.NET supports C #, Visual Basic .NET, AND ANY Other Language In The Microsoft .NET Family. ASP.NET Provides Six Types of Validation Controls. They Are

CompareValidator CustomValidator RangeValidator RegularExpressionValidator RequiredFieldValidator ValidationSummary Each of these above controls can be linked to .NET Web Form controls like TextBox, Dropdownbox, ListBoxes etc. Even though there are wide ranges of controls for validation, it is up to you to decide upon which control to use. It also depends up on your project needs. In this first part of this series, you will learn the application of first three controls with code listings using VB .NET and C #. CompareValidator As the name suggests, this control is used to compare the values ​​of one control with another control. The comparison is done with the help of textboxes. The CompareValidator control has two important properties namely, Operator and Type. The Operator property is mainly used as a basis of comparison between two values ​​(GreaterThan, LessThan , Equal, Notequal etc) and Type Property INDICES The Data Type of the Values ​​Like Integer, String Etc. To Illustrate, COPY O r enter the code in Listing 1 and save the file with extension .aspx under the Inetpub / wwwroot directory. Be sure to install .NET Framework SDK or Visual Studio .NET before attempting this work. I recommend that you use ASP.NET WebMatrix for coding and testing the listings shown on this article (See figure 1). If you are using this tool, then you need not worry about giving extensions, setting the language etc. The tool does the entire work for you. It also includes a built -IN Server, Which Can Be Activated Upon Pressing The F5 Key. You Can Also Set Various Properties from The Ide Itself and The Coding IS Automatically Done in The Background.

Moreover, The Tool Does NOT EAT UP YOUR VALUABLE DISS (www.asp.net) And install. After all, it's free from microsoft click Here for larger Image <% @ page language = "VB"%>