views:

53

answers:

1

I use the ASP.NET validation controls in an ASP.NET web forms environment. Is the better approach to keep all of the validation rules server-side, such as using AJAX to validate a field, without posting the whole page back.

I found one control called ValidatorCallout ( http://www.asp.net/ajax/ajaxcontroltoolkit/samples/ValidatorCallout/ValidatorCallout.aspx ) but was trying to figure out if there was a better approach.

A: 

You should always perform Server side validation, regardless of whether you do any client side validation. This is because there are many ways around clientside validation, such as switching js off or sending a custom built request that doesn't use your page.

It is a good goal to use the same validation rules on both client and server. xVal is a good option for this.

Daniel Dyson
Thanks for looking at this older question. Basically I wanted to get away from the running the whole page client valiation because the Validation Controls create a ton of JavaScript calls. I was looking for a solution where I could just have my validation rules in my business objects, but use AJAX to simulate client side validation via partial page postbacks. The server side validation would always be in place.
Josh
No problem. Using AJAX to call the Server side validation code is a good compromise. The nice thing about xVal is that you can pick and choose between a number of clientside and server side implementations. xVal performs the translation. I personally prefer to use jQuery Validation on the client ans FluentValidation on the Server. The jQuery validation rules are emitted by xVal, based on the FluentValidation rules.
Daniel Dyson
I'm currently using Web Forms, not MVC, but for my next project I'll like use MVC and take a look. It doesn't look like xVal has been updated in year. Is it still an active project?
Josh
Not sure about how active it is. You would have to contact the developers on it.
Daniel Dyson