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

Introduction

Validation in ASP.NET

Published 09/21/01 - For ASP.NET

Introduction

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
Comment:
Thanks for such quick review ....
Title: GOOD   
Name: NAGESH
Date: 2004-07-13 8:28:00 AM
Comment:
But where is the code!!!!!!!!!!!!!!!!!

Product Spotlight
Product Spotlight 





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


©Copyright 1998-2017 ASPAlliance.com  |  Page Processed at 2017-03-23 10:22:38 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search