I'm working on an application that has a large number of inputs for certain types (50 money inputs, 30 date inputs etc).
I have been creating an Com开发者_Python百科pareValidator
for each one to make sure users are putting in the correct information but I am curious if there is an easier way to create the validation once and apply it to all desired inputs?
Writing out 80 validators that do basically the same thing seems like a waste. Am I missing something that already does this in .NET or are there anything out there that can make validation easier?
Note: All validation needs to be done on both the client AND server side. I've read a little about ASP.NET MVC validation but unfortunately that won't be an option here.
You might want to give the CustomValidator control a look. According to the MSDN document
It is possible to use a CustomValidator control without setting the ControlToValidate property. This is commonly done when you are validating multiple input controls or validating input controls that cannot be used with validation controls, such as the CheckBox control. In this case, the Value property of the arguments parameter passed to the event handler for the ServerValidate event and to the client-side validation function always contains an empty string (""). However, these validation functions are still called, where appropriate, to determine validity on both the server and the client. To access the value to validate, you must programmatically reference the input control you want to validate and then retrieve the value from the appropriate property. For example, to validate a CheckBox control on the server, do not set the ControlToValidate property of the validation control and use the following code for the handler for the ServerValidate event.
精彩评论