开发者

Field validators in asp.net

Is it possible to have "Required Field Validator" controls to validate more than one field (example I have 12 te开发者_如何学Cxtboxes 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.?


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.


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.


Multiple Fields Validator - An ASP.NET Validation Control is what you need.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜