views:

73

answers:

4

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?

A: 

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.

Jan Zich
+1  A: 

You can use following Validators in ASP.NET

  • RequiredFieldValidator,
  • CompareValidator,
  • RangeValidator,
  • RegularExpressionValidator,
  • CustomValidator,
  • ValidationSummary

See here for more details.

Henrico Dolfing
I think it's better to look http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.aspx and http://msdn.microsoft.com/en-us/library/9eee01cx.aspx
abatishchev
A: 

If shorty, yes, CustomValidator.ServerValidate

abatishchev
+1  A: 

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).

UserControl