如果自定义验证器已经具有 clientValidationFunction,是否需要 ServerValidate 事件
据我所知,如果客户验证器中有 clientValidationFunction 。在该值有效之前,它不会让回发发生。因此,如果已经有 clientValidationFunction,则不需要有 ServerValidate 事件,对吧?
As far as i know, If there is clientValidationFunction in a customer validator. it will not let the post back happen until the value is valid. So if there is clientValidationFunction already, it is not needed to have a ServerValidate event right ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您永远不应该依赖客户端代码来执行验证。客户端可能禁用了脚本,因此您的验证代码可能根本无法运行。此外,还可以通过许多其他方式规避客户端代码。
客户端验证对于避免字段无效时往返服务器很有用,但您仍然必须执行服务器端验证以实际确保客户端已发送有效数据。
You should never rely on client-side code alone to perform validation. The client might have scripting disabled, so your validation code may not run at all. Moreover, client-side code can also be circumvented in many other ways.
Client-side validation is useful to avoid a round-trip to the server when a field is invalid, but you still have to perform server-side validation to actually ensure the client has sent valid data.
如果您尝试触发
CausesValidation
属性已设置为 true 的控件的事件,情况就是这样。但是,如果CausesValidation
已设置为 false,则会发生回发。即使已通过调用
validator.Validate()
将CausesValidation
设置为 false,您也可以强制验证器调用其验证逻辑。That is right in case you are trying to fire an event of a control with a
CausesValidation
property that has been set to true. However, ifCausesValidation
has been set to false a Post Back is going to happened.You can force the validator to call its validation logic even if the
CausesValidation
has been set to false by callvalidator.Validate()
.你说得对。当由于复杂性而无法创建客户端规则时,应使用服务器验证。您可以在这里阅读一些更多内容
You're right. Server validation should be used when you can't create - because of complexity - a client rule. Here you can read some more