Validation in ASP.NET
page 1 of 9
Published: 23 Sep 2001
Unedited - Community Contributed
This article introduces the concept of Validataion in ASP.NET and explores the many ways to do it with the controls provided.
by . .
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 36461/ 100


Validation in ASP.NET

Published 09/21/01 - For ASP.NET


When you have a form that user's submit data, its important that they don't mess it up and enter weird stuff. Validation stops this but in ASP it was a tedious job of If statements to work out. I myself had a simple form that added users to a database, it had a heck of a lot of if statements. ASP.NET introduces - Validation Controls. These controls are just like Web Controls and can do many things like - Check if a field is filled out, Compare a field to something (or another), Use regular expressions on a field, Check to see if a field is within a certain range, you can even create your own!

Before we begin

Now, this is going to be a pretty big article/tutorial so lets get some of the common stuff out first.

Validation Controls only work for the following controls:

  • HTMLInputText

  • HTMLTextArea

  • HTMLSelect

  • HTMLInputFile

  • TextBox

  • ListBox

  • DropDownList

  • RadioButtonList

But what other controls could you use it on? Yes there are many more, but its rather hard to do everything in one. Next, the control syntax takes the form of -

<asp:ControlName runat="Server" ControltoValidate="ControlName" ErrorMessage="Message" OtherProperties />

(Remember that the italics stuff is stuff that you change). Now its pretty obvious what ErrorMessage is (its the message that's displayed if it turns out that the field isn't valid). ControltoValidate is the id of the control that your going to be checking. One last thing, here is a page that I've created that uses Validator Controls. Try the following to see what errors come up:

  • Enter no name.
  • Enter only a first name.

View Entire Article

User Comments

Title: Nice   
Name: Nagesh
Date: 2004-07-13 9:49:31 AM
Thanks for such quick review ....
Title: GOOD   
Date: 2004-07-13 8:28:00 AM
But where is the code!!!!!!!!!!!!!!!!!

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-06-23 9:01:48 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search