Solving the Challenges of ASP.NET Validation
page 1 of 7
Published: 01 Aug 2005
Unedited - Community Contributed
Abstract
Validating user input is an important requirement of most web applications. However, many ASP.NET developers find the standard ASP.NET validation controls to be either hard to use or lacking in features. Peter Blum answers the most frequently asked questions concerning ASP.NET validation.
by Peter Blum
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 253900/ 452

I have been working with the ASP.NET validator controls commercially almost since ASP.NET 1.0 was released. In the process, I created a number of my own validators based on the System.Web.UI.WebControls.BaseValidator class for my customers to use. I was never happy with the flexibility of the overall validation framework. So I built my own validation framework, Professional Validation And More, and have been focused on the challenges developers have faced with the original validators so that my software is the best solution available. In particular, I regularly answer questions posted on the forums at www.asp.net. This article will identify the common questions raised and offer answers.

The ASP.NET validators lack features that are common real-world situations. For so many situations, the answer is to abandon the existing validator and write your own using a CustomValidator. Also, developers are limited by the client-side JavaScript of the ASP.NET validators and cannot enhance their user interface to provide nice tricks like changing the background color of the field with the error or prompting with an alert. I've found that custom code and hacks are the rule instead of the exception. Microsoft has too and has provided a few enhancements in ASP.NET 2.0 which I'll address. For a list of the 27 limitations I've found with the ASP.NET validators, go to www.peterblum.com/vam/valmain.aspx.


View Entire Article

User Comments

Title: fsdfs   
Name: sdfsd
Date: 12/19/2012 3:34:55 AM
Comment:
sdfsdf
Title: gfgf   
Name: gf
Date: 12/8/2012 1:34:49 PM
Comment:
gf
Title: tyty   
Name: tyty
Date: 10/31/2012 6:24:26 AM
Comment:
rtyrtyy
Title: sfdgsdf<   
Name: dsf
Date: 10/25/2012 11:20:47 AM
Comment:
c
Title: title   
Name: name
Date: 10/12/2012 5:03:07 PM
Comment:
xxx
Title: show the clander when i click in textbox in asp.net   
Name: prabh mangat
Date: 5/5/2012 3:43:34 AM
Comment:
pls give me the code or help me.....
Title: tooooooooo pooooooooooooor code   
Name: Rahul
Date: 4/11/2012 1:39:02 PM
Comment:
I want to know the confirm box will display after validation...............................
Title: Thanks and Question   
Name: rajesh
Date: 4/13/2010 5:46:29 PM
Comment:
One peculiar thing I find here is.

When I use like this it works
OnClientClick==”if (!confirm('[your message here]')) return false;”
But when I put the same code in a function and call the function here, it does not work.
Lets say, I put the above code in a function foo(); and use it as below
OnClientClick=" foo();” -- Cancel or Ok both postbacks without client validation.
OnClientClick="return foo();” -- Cancel works but Ok postbacks without client validation.

Strange. Or I lack info .
Title: Thanks   
Name: suhas
Date: 4/7/2010 7:24:00 AM
Comment:
Hi,
Thanks grea888 post. u saved my day.
Title: Question   
Name: AYA
Date: 12/30/2009 10:05:08 AM
Comment:
Hi there,

first of all thank you very much for your clear illustration,

but i faced a problem with validation,

here is my question

how can i do validation on the formview (when i click Update)
Title: Best   
Name: komal
Date: 10/21/2009 7:05:37 AM
Comment:
Thank u So Much It"s Help me to Solve my Problem.
Title: This help me a lot...   
Name: sunil kumar mishra
Date: 10/20/2009 5:13:44 AM
Comment:
Thanks a lot...
I was in a big problem... , I used a confirm message while finally save the payment details in University pannel. But it neglected the validation.....

Through this article i am able to do so....

Thank You
Title: Give me advice   
Name: anu
Date: 9/23/2009 2:53:25 AM
Comment:
hi,
i am a beginner with asp.net now i want to develop
a web side just for improving skill but i don't know
how i will start work
Title: Thanks a million   
Name: user
Date: 9/4/2009 3:23:55 AM
Comment:
One of The Best Article !!!
Title: JC   
Name: James
Date: 7/21/2009 8:03:09 PM
Comment:
Excellent Artical..thanks!
Title: thank you   
Name: Mark
Date: 6/16/2009 9:35:49 AM
Comment:
Very nice work, thank you. :)
Title: .net2.0 TextBox.CausesValidation   
Name: Jian
Date: 3/16/2009 2:37:40 AM
Comment:
TextBox.CausesValidation is a new property in .net2.0 and the default value is false. Remember to set it to true if you want valication running when postback.
Title: Error   
Name: sameer
Date: 2/5/2009 1:41:12 PM
Comment:
there is a bug when we use both of them I am using confirm when i submit to prompt the user if ok or cancel and the validation summary as well, but this is what happens

when i use return confirm([message]) it prompts the user with ok or cancel but doesn;t validate, any thoughts
Title: An unresolved issue   
Name: Andrey
Date: 12/2/2008 2:28:03 PM
Comment:
I have been lookin a lot to find a solution for a simple problem.
How does one trigger validation from javascript on client side.
I would like to erite something like:

{
ValidatePage();
if (Page_IsValid)
dosomething();
else
dosomeotherthing();
}

Sadly there is no equvivalent to ValidateDate()
Title: Thanks!   
Name: Jane
Date: 10/28/2008 6:26:03 AM
Comment:
That answers all sorts of questions that I didn't previously know enough to ask.
Title: Thank you!   
Name: Jorge Rojas
Date: 9/20/2008 8:55:28 PM
Comment:
Your suggestions about supporting globalization in validators really work. Thanks a lot.
Title: ASP.NET   
Name: Ravindra
Date: 9/17/2008 4:51:58 AM
Comment:
just i want to know thE asp.net FAQ'S
Title: Thanks a lot...   
Name: Shebin
Date: 9/12/2008 2:28:34 AM
Comment:
I am beginer in this ASP.NET field....
Whwn I started with ASP.NET I have got a lot of doubts..
I got solution for a lot of doubts from this article...
Thanks a lot....
Title: Thanks   
Name: Jibi
Date: 5/8/2008 4:06:25 AM
Comment:
Thanks for this article. It solved my problem.
Title: Good!!   
Name: Sathish Kumar (Dhanus Technologies)
Date: 3/25/2008 7:45:12 AM
Comment:
Good..! Expect lot for begineers
Title: How to give validation for post-box number, mobile number in india,   
Name: pavan dhakate
Date: 3/7/2008 4:38:15 AM
Comment:
hi,
i have some problem regarding giving validation to post box number n mobile/telephone numeber in india
plz give some regular expressions to solve this problems
Title: super   
Name: sakthi
Date: 2/19/2008 1:30:24 AM
Comment:
Not bad.
Title: Cool   
Name: Tim Stover
Date: 12/31/2007 6:05:59 AM
Comment:
great
Title: Thanks so much!   
Name: CH
Date: 11/23/2007 3:49:44 AM
Comment:
I finally found this article that saved me!

I was unable to make my validation work after adding the confirm box!

Imagine I was stuck for 2 weeks? assigning hidden fields, postbacks...etc etc...

This article should be carved out on a piece of rock and displayed for posterity!

Thanks so much!
Title: 1.1 is the Worst!   
Name: Joe Gakenheimer
Date: 10/11/2007 3:44:44 PM
Comment:
I have had it with the 1.1 version, I mean having to check each validation at the server to trip the event handler is nonsense. I have a project that I am doing maintenance on and all I needed was to add a Button Link; this app is predominately button links. Well about a minute after I put it into production, my buttons all of a sudden come to life as validators. Naturally, this did not occur in Firefox, but I had to go through a rush a build out with the buttons commented out and replaced with HTML links.

The 2.0 ASP.Net is worlds better and I can't wait to get on a good project; plus the validations work, along with ValidationGroup.
Title: This is so great!!!!!!!!!   
Name: Samantha
Date: 9/5/2007 3:28:36 AM
Comment:
This is so so great! thanks a bunch...i've been spending few days trying to get the validation to work on my site...bam! only 1 line n it works miraculously! great site!
Title: Nicely Done!!   
Name: Masquinyo
Date: 8/3/2007 9:58:39 AM
Comment:
What an excelent article, it has helped me with my struggles.
Title: Great Great Great   
Name: Prashanat Bhopale
Date: 8/1/2007 5:35:58 AM
Comment:
Really a nice article which help me to learn a lot
Title: Thanq   
Name: Anil
Date: 7/26/2007 5:48:29 AM
Comment:
Wow, what a wonderful article. You solved my biggest head aches. Thank you very much!!!!!!!!!!!!!!!!!
Title: Thank you.   
Name: Peter
Date: 7/3/2007 10:32:18 AM
Comment:
As I have been working on a quite large e-CRF and used validators, while being (relatively ) new to asp.net. And I must say that your article really claryfied alot.

So, thank you!
Title: great   
Name: iru
Date: 4/9/2007 6:09:36 AM
Comment:
thnks ur site provides boost to developers
Title: Displaying alert or confirm after validation   
Name: Rotem
Date: 3/29/2007 10:50:54 AM
Comment:
For those of you who would like to display an alert/confirm message AFTER validation...check out this link:

http://aspalliance.com/357_Add_Confirmation_After_Controls_Validation_on_Client

now go fourth and validate!!!
Title: peer   
Name: lopez
Date: 3/20/2007 9:38:58 AM
Comment:
Excelent article.
Title: Cheers   
Name: Da Koda Code
Date: 3/13/2007 11:15:31 AM
Comment:
This is nutzzz. I spent 1/2 a day debugging this stuff and all I need to add was the statement you recommmended

if (Page.IsValid)
{
{

Cheers dude. Wish I had spotted this earlier. Sweeeeett!!1
Title: Thanks   
Name: musmanjaved
Date: 3/10/2007 2:59:17 PM
Comment:
hello sir,

Your site gives great help.Best of luck!.

Thanks n take care.
M Usman Javed.
Title: Its Great   
Name: Yogesh Mahajan
Date: 3/9/2007 4:28:55 AM
Comment:
Really Thanks ..for this
Title: Wonderful   
Name: Randy
Date: 2/15/2007 6:32:32 PM
Comment:
Wow, what a wonderful article. You solved my biggest head aches. Thank you very much!!!!!!!!!!!!!!!!!
Title: THANX!!!   
Name: Daniel Hofmann
Date: 1/8/2007 10:38:10 AM
Comment:
After spending several days on the problem that empty textboxes are not validated, this article solved my problem. Thank you!
Title: Great Help   
Name: Vinod Kumar Sasaram(Kus)
Date: 12/13/2006 4:46:25 AM
Comment:
It is an excellent site for help.
Please also give some code with sql server that help in project development
Title: group validate   
Name: siva
Date: 11/22/2006 12:50:14 AM
Comment:
i want group validate in vb code.
Title: Such A gr8 Article,useful to all   
Name: Sanjay Sharma
Date: 11/10/2006 12:54:58 AM
Comment:
This is really a gr8 article and it helps me a lot to learn about validators. one more thing i want to ask that if i want two diff messages in the validation summary control- one for required field and other for compare validators on the single button click.
Title: thanks you   
Name: RemoBrian
Date: 11/8/2006 5:27:35 PM
Comment:
Your article was a great help. Thanks so much.
Title: Thank you so much!!!   
Name: Marisa
Date: 10/26/2006 11:19:58 AM
Comment:
I've been struggling with the 2.0 validator for several weeks now. On the new version of Firefox the validation code was called AFTER my submit button's on_click event, very frustrating, because my database calls were going through before it put up the error message or had a chance to stop them. I finally realized it was calling server-side validation, but couldn't figure out what to do to resolve my issue.

Your article explained how I can check for validation in my button.

Thank you so much!!!
Title: Well presented   
Name: Sreehari
Date: 10/19/2006 5:20:17 AM
Comment:
The info is really breif and well presented.
Title: Buttons do not submit(Great Article)   
Name: Farrukh Mehmood
Date: 10/12/2006 12:18:21 AM
Comment:
Thanks Paul Wilson and Thomas Freudenberg for posting such information on net.for last two week i am facing this problem and i become to much tied to find the solution of this problem.
at last visit this link and find the solution thanks once again

Farrukh Mehmood
Title: Good   
Name: Merlin
Date: 9/25/2006 3:09:27 AM
Comment:
You are doing a gr8 job here..Keep up ur good works..
Title: Need a little more...   
Name: Jportela
Date: 9/18/2006 12:28:23 PM
Comment:
I'm having a curious issue, some of my users see the validators message when a missing field is required or when a regular expression is not matched, but even they see the message and also a validation summary, they can still submit the form. Anyway this article is good.
Title: How can I avoid postback before validation???   
Name: Joar
Date: 7/18/2006 5:51:04 AM
Comment:
If I add a OnClientClick="return confirm('Save?');" to a submit button, the validation I have specified in the validation control is done AFTER the postback to the server!!!
How can I avoid that!!!
The point is not to postback before validation!!!
Title: Great article   
Name: on Paal
Date: 7/10/2006 8:05:34 AM
Comment:
This helps a lot. It also points to why .net is not only hard to learn, but with all the glitches like validation
Title: Very useful article   
Name: Sudhir Kumar
Date: 7/6/2006 8:07:00 AM
Comment:
I was facing problem that my web form was not submitting and not validating. But i got very good solution on this web site. Now submit button is working as well as client validation is also working.

In Last! This is very gud ARTICLE.

Thanks to author.
Title: Excellent   
Name: snehal
Date: 7/4/2006 7:50:31 AM
Comment:
Its an excellent article.
Title: Extremely cool article   
Name: tientrinh
Date: 7/3/2006 7:00:30 AM
Comment:
Thank you very much, good articles.
Cảm ơn rất nhiều, bài viết này quá hay.
Title: it solves my problem   
Name: Iqbal singh
Date: 7/3/2006 1:15:42 AM
Comment:
Earlier controls were not validated at fire fox
Now it works with simple tric of server side validation
thanx
Title: Very Good Article   
Name: Santosh Kumar Devaki
Date: 6/20/2006 1:42:44 AM
Comment:
This is a very good article, it helps me a lot. I solved many problems by studying this article
Title: Validation in ASP.Net   
Name: Pankaja
Date: 6/10/2006 2:36:20 PM
Comment:
Hi,
The article is interesting, I have to go back to work on monday to see if the steps mentioned in the article are followed. The scenario is, I have 4 image link buttons on the screen, only one of them has causes validation set to true. All 4 of them have enabled and visible (design time) properties set to true. But when the page is rendered none of the buttons show up. Sometimes a few tries of tabbing from field to field(which causes autopostback), the buttons appear. This has become a critical isssue for us as our product is in the User Acceptance phase and we are running on a busy server. Any help is greatly appreciated. Please respond to
pankaja_shankar@ml.com

Thanks,
Pankaja
Title: Validation Controls   
Name: Swaroop
Date: 5/2/2006 8:06:10 AM
Comment:
Really a very good article !! Thank you
Title: Great Help   
Name: neoms21
Date: 4/26/2006 8:57:29 AM
Comment:
It helped me a lot.
Kudos for writing such a article.
Title: Mr   
Name: Mani
Date: 4/18/2006 6:56:11 AM
Comment:
This article is excellent and very useful those who are not familiar with .Net.

Thanks a lot for the support.

cnmayyanar@yahoo.com
Title: menu control using javascript in asp.net   
Name: shri
Date: 4/11/2006 7:54:10 AM
Comment:
i need coding for this project. Any one pls help me
Title: If ... then ... validatiors   
Name: Filip
Date: 3/16/2006 5:03:21 AM
Comment:
HI there,

How do you handle situations where validation of a certain "group" is dependant on another control(s) value. For instance - only validate if I have entered my email address if I have opted to sign up for something (i.e. check a checkbox of some kind)
Title: we are already in asp.net2   
Name: gopinath
Date: 2/20/2006 3:59:57 AM
Comment:
No Use Now
Title: Thanks :)   
Name: Targos
Date: 1/27/2006 1:04:52 PM
Comment:
That's great. But if i would like to use validationsumary messagebox with a button which use onclientclick confirm. The sumuray messagebox is display after the confirm box...
Can i manage the order ?
Title: Fantastic   
Name: Ralph Carney
Date: 1/5/2006 6:55:14 AM
Comment:
thanks for the help
Title: Is Alert possible with ASP.Net 2   
Name: Abhishek dave
Date: 12/24/2005 6:22:25 AM
Comment:
hi,
IN .net framework 2 i need to alert the error message
using the given validators,
I have read a ppt from microsoft that in .net 2.0 there can be no hand-editing of WebUiValidator.js and I can't even find it as its encapsulated in webresource.axd
So Mr Peter Blum.
How to handle this challenge,
please help me out in this

regards

abhishek
Title: Excellent Article   
Name: Manoj
Date: 12/13/2005 1:23:16 AM
Comment:
This is really very very usefull article for all level of software developer on .NET technology. Thanks!
Title: Great Article   
Name: Chital
Date: 12/10/2005 5:11:33 AM
Comment:
Really helpful for .Net developers.From this i came to know all the properties of Validators of ASP.net...WONDERFUL!!!!!!!.......Thanks....
Title: Mr   
Name: Dave Sexton
Date: 11/30/2005 5:42:21 AM
Comment:
My hosting company updated to SP1 and then none of my forms worked - but thanks to this article I have fixed the problem. Many thanks.
Title: Very Useful & Important   
Name: Gurvinder Singh Manjotra
Date: 11/30/2005 1:56:34 AM
Comment:
Very funny as I thought that validation work only in IE browser but this supports me a lot in doing same as Server Validation in other browsers also. My email as gs_manjotra@yahoo.com

Thanks
Title: programmer   
Name: s1
Date: 11/25/2005 1:12:20 AM
Comment:
quiet good for the beginers
Title: Explains it all.   
Name: Andy
Date: 11/15/2005 6:44:26 PM
Comment:
For anyone looking to get an understanding of what the validation controls do and don't do, this is the article to read.

.Net 2 solves a lot of the problems everyone will be pleased to know.
Title: Superb   
Name: ABC
Date: 11/11/2005 2:39:27 AM
Comment:
Very good.It solves my problem
Title: Good Work   
Name: Nauman
Date: 11/9/2005 6:48:15 AM
Comment:
Very helpful material.
Title: Just Superb!!   
Name: Sandesh kp
Date: 11/5/2005 5:06:52 AM
Comment:
Its just superb article for beginner as well as proffesionals. Thanks a lot for giving such article
Title: thanks for sharing your knowledge   
Name: neildotnet
Date: 11/1/2005 12:19:50 AM
Comment:
Excellent article, i erroneously assumed the server side validation was handled automatically! this was by reading other tutorials/articles which brushed on the issue, but stated that server side validation would always occurr regardless. Working on IE also made me assume server side validation was occuring, when it must have been the client side.
Title: Very Good   
Name: RaviKumar
Date: 10/25/2005 9:12:52 AM
Comment:
It is a very good article teaching many points about validators which can be implemented with no effort.
Title: What if....   
Name: Liam
Date: 10/19/2005 4:18:42 AM
Comment:
Not bad....but what if we have a control that for whatever reason dosn't support CausesValidation, in our case the TabStrip control. How do we force the validation to kick-in client side before the SelectedIndexChanged event fires?
Title: Just Thank You!!   
Name: Goran
Date: 10/17/2005 3:11:20 PM
Comment:
No more explanation needed about page validation.

Totally helpful
Title: Cool   
Name: Vikrant Kaul
Date: 10/17/2005 5:00:47 AM
Comment:
Thanks for that great summary presentation. It was excellent help for me.
Title: Nice Article   
Name: sundaramurthy.J
Date: 10/4/2005 3:40:42 AM
Comment:
Before i used javascript validation for popup message after seeing this article now iam started to using the Validation controls
Thanks for explaination
Title: Best Best Best for validation   
Name: Mohsen Eslamifar
Date: 9/27/2005 6:11:16 AM
Comment:
i just say what a beautiful article
Title: Great Article   
Name: James
Date: 9/18/2005 3:27:23 PM
Comment:
Thanks for the article. The automatic call to validate the page on buttons and such was driving me nuts.

Of course it had to be something so simple as an attribute. Why didn't I think of looking for that?
Title: Two sets of controls on the same page   
Name: Nanda
Date: 9/15/2005 9:01:12 PM
Comment:
Ur page answers my question. Thank u very much
Title: Two sets of controls on the same page   
Name: Nanda
Date: 9/15/2005 6:41:58 PM
Comment:
I haave two sets of controls on the same page. The user can select either one. say ..Register new Or Login. But the validation controls fire for both making it hard to leave the other set free..How do i manage this? ASP.NET 1.1
Title: very bad   
Name: peter
Date: 9/13/2005 8:26:15 AM
Comment:
this is not quite information to learn asp.net
must have provided a lot.

see u soon
Title: superb   
Name: ankit
Date: 9/13/2005 8:23:18 AM
Comment:
this helped me a lot to learn asp.net.
thanks a lot.
Title: Just what I needed   
Name: Jenny
Date: 8/27/2005 12:22:31 AM
Comment:
This is great. No text book in the world can replace knowledge. Was using calendar controls to assist in validation but now can make my pages much less ugly.
Fantastic
Title: prgmer   
Name: Kathy
Date: 8/24/2005 2:48:22 PM
Comment:
Excellent!! Helped Me a lot:-)
Title: Programmer   
Name: Jim
Date: 8/21/2005 11:28:55 PM
Comment:
Awesome! Just awesome! Thank you so much for making this info easy to consume.
Title: Very Nice   
Name: Anuj kumar
Date: 8/19/2005 3:45:25 AM
Comment:
I am a new user of asp. net . i want to know that how to use class in asp.net using script language vb.net
Title: Great article   
Name: Jon Paal
Date: 8/5/2005 4:38:52 PM
Comment:
This helps a lot. It also points to why .net is not only hard to learn, but with all the glitches like validation, it's also frustrating.

thanks for the explanantion, in spite of the shameless plug.

Product Spotlight
Product Spotlight 





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


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 8/28/2014 7:04:20 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search