Which is the best method of Validating in web applicaiton...
Hi all,
Basically i am windows Programmer means working only desktop application. so entirely new to the web application. I have a basic idea about that. Can any one tell me how to handle the validation part in the web application (Asp.NET) like Client side validation using java script or Server side validation using the code behind or using Validator controls (javascript). Let me know which is the best method to achieve the performance and good programming techniques.
Any suggestions and help would appreciated!!
Thanks & Regards,
Mahes
Re: Which is the best method of Validating in web applicaiton...
Client side validation is useful since it saves the users of having to go through postbacks, but one of the rules of thumb is to not assume that it is the be-all and end-all for your validation. Never trust user input. So you must validate on serverside as well.
Re: Which is the best method of Validating in web applicaiton...
It's best to do as much client side as possible, since, as mendhak said, eliminating the need to go back and forth to the server is a timesaver.
My general rule of thumb is that if it's quick and easy, do it on the client side with javascript, otherwise do it server side. Things like making sure that a textbox isn't empty or is at least 10 characters, I do on the client. Anything more complex, I do on the server.
Even things like making sure something is formatted correctly, I like to do on the server. It's very possible and quite easy to do most of them client side, but it's far harder to debug and step through client side code than it is to do it on the server. Anything that requires more than a trivial application of logic should be put there.
Re: Which is the best method of Validating in web applicaiton...
I agree. do client side validation first with "requiredFieldValidator", "customValidator" (asp.net 2005) controls and either set them to display the text error or use a validationsummary control which summarizes all the errors. These controls require some regular expressions.. just search the net for how to create reg exps... Also if you are using asp.net 2003 the validation controls dont work in FireFox. But google Dom validators... a guy created a dll that actually works in FF. the dll is called DomValidators.dll. As for server side validation, you need to do this a well. Protect your server/data/app!
Re: Which is the best method of Validating in web applicaiton...
Thanks for your valuable suggestion..
It really helps me to work with the validation part in the web applications.
Thanks & regards
Mahes