Question

Is it possible to have "Required Field Validator" controls to validate more than one field (example I have 12 textboxes that are required. I want to try an avoid having 12 RFV controls. If a validation does get triggered, is there a way to display a customized message ("textA is empty" or "textB is empty") etc.?

Was it helpful?

Solution

You can create a custom validator that goes through validates all the controls.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.aspx

The Required Field Validator can only validate one control at a time.

OTHER TIPS

You cannot do that with a RequiredFieldValidator; you could write your own CustomValidator to do that, but the validation would be on the server side rather than on the client side.

As mentioned by everyone else you can create your CustomValidator that can validate on the client side and on the server side. There are couple of things that you must keep in mind.

1) Make sure to expose your client script as a Web Resource. This will enable the script to be cached by the browser.

2) Use a certain attribute to target certain TextBoxes. This can be performed by giving them a certain class which will be validated in your Custom Validator control.

Hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top