开发者

How do you have one asp.net validator tied to multiple controls?

开发者 https://www.devze.com 2023-01-03 05:17 出处:网络
I have 4 textboxes which can only take a number.The problem is tha开发者_Python百科t I have to create 4 separate validators for the controls and associate their id with the validator.Is it possible to

I have 4 textboxes which can only take a number. The problem is tha开发者_Python百科t I have to create 4 separate validators for the controls and associate their id with the validator. Is it possible to have just one asp.net regular expression validator and associate all the controls with that one validator?


You could use CustomValidator and write your own validation code. The clientside code could hypothetically access each text box and check them against the regex...

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

A simpler solution if you don't want to have to include the regex in 4 places is to store the regular expression in the code-behind and apply it to all the validators during Page Load? Not a perfect sol'n but would work. You could also apply a standard error message and other formatting options in the code-behind.


No, because each validator has a "controltovalidate" property that can only be set to a single value. The only exception is the CustomValidator

0

精彩评论

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

关注公众号