A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Performing custom validationDemonstrates how to use custom validation on a form by checking to see if a string in a TextBox is not the same with a string from an array (or database), case in which it displays 'This name is already taken'. |
On Wednesday, August 11th 2004 at 04:57 AM By Andrew Pociu (View Profile) ![]() ![]() ![]() ![]() (Rated 4.3 with 16 votes) |
|||
|
You'll often want to use custom validation to validate a control on a webform. Perhaps when a user registers on your website you want to check the database to see if the name he wants to register doesn't already exist. If you don't know the basics of form validation, first read the tutorial named 'Validate using RequiredFieldValidator'. Start a new ASP .NET Web Application project named customValidation and drag a TextBox, a Button and a CustomValidator to WebForm1.aspx. Now set the ErrorMessage property of CustomValidator1 to "This name is already taken". Also set the ControlToValidate property to TextBox1. Now let's get into the C# code. We won't bother with a real database in this project, we will replace it with an array that holds 3 names. So in the public class WebForm1 make a string array:
Now we'll use the following code to loop through the array and check to see if the name inside the TextBox matches one of the values in the array:
At this time we only need to set the ServerValidate event to validateName. We'll do this using the Properties window of Visual Studio .NET: ![]() ...and that's all! Open the webpage and see for yourself - enter one of the names: 'Van Nostrand', 'Vandelay' or 'Pennypacker' and you'll get the error: ![]()
|
||||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
||||
|
||||
Current CommentsI have no ServerValidate Property for my customValidator control in VS.Net 2003?
Custom Validation in Asp.Net : Get input only integer with float value
It\'s grate solution u have provided but same i want to get by using database will u plz provide me solution or hint because i spent my whole day in that.
Excellent tutorial. Its really helpful.
Thanks,
Ujjwal B Soni
thank u
its very nice......
Related Tutorials
Related Source Code
ASP.NET Job Search