问题描述
我有一个包含密码"和确认密码"文本框的Web表单.我将RegularExpressionValidator附加到第一个,并将CompareValidator附加到第二个.现在的问题是,当我在密码"字段中有内容,而在确认密码"字段中没有任何内容时,它不会显示字段不匹配的错误.一旦我在确认密码"字段中输入内容,它就会显示错误.我也想允许将两个字段都留空.
I've got a web form with Password and Confirm Password text boxes. I've got a RegularExpressionValidator attached to the first one and CompareValidator to the second one.Now the problem is when i have something in the Password field and nothing in Confirm Password field it does not display an error that fields don't match. As soon as i put something in the Confirm Password field it shows the error.I also want to allow to leave both fields blank.
我正在使用.NET 2.0
I'm using .NET 2.0
可能是什么?
推荐答案
FWIW,如果将密码"框设为ControlToValidate,将确认密码"框设为ControlToCompare,则它将起作用,因为密码框中将包含一些内容,并且因此将运行验证.
FWIW, if you make the Password box the ControlToValidate, and the Confirm Password box the ControlToCompare, then it will work because the password box will have something in it and hence will run the validation.
当然,这可以使他们提交带有空的密码"框和填写的确认"框的表单,因此将必需的验证器放在这两者上可能是一个更好的主意.
Of course, this could allow them to submit a form with an empty Password box and a filled-in Confirm box, so putting a required validator on both is probably a better idea.
这篇关于ASP.NET CompareValidator问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!