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
精彩评论