what are the ways to do server-side validation in an asp.net web form? Using custom validator and it's serverValidate event? or what else?
I have always been a proponent of homemade solutions. So you can do it also the old school way: validate before you save directly in code (maybe separate the validation to its own function for cleanliness). To be honest, I have never understood why this method is being so frowned upon, and why we needed to invent the validation methods. It has one big advantage: all validation is in one place; you don’t need to hunt around. Also, in some cases the validation logic may become so complicated that this is the only reasonable way.
You can use following Validators in ASP.NET
- RequiredFieldValidator,
- CompareValidator,
- RangeValidator,
- RegularExpressionValidator,
- CustomValidator,
- ValidationSummary
See here for more details.
All standard ASP.NET validators perform both client-side and server-side validation. If you don't need the former (enabled by default) set their EnableClientScript property to false. The server-side validation is performed when you call Page.Validate() or the postback was triggered by a control with CausesValidation property set to true (ValidationGroup is in game here).