它控制触发Page.IsValid =假? [英] Which controls triggered the Page.IsValid = false?
问题描述
两件事情:
-
是否有可能通过jQuery来设置Page.IsValid(Is_Valid)财产,让我不要有使用ASPX验证?这是我的理解是,IsValid属性为只读?
Is it possible to set the Page.IsValid (Is_Valid) property through Jquery so that I dont have to use the aspx validators? It is my understanding that the IsValid property is read-only?
在验证器都在,才可能找到答案,通过jQuery的(ofcourse),其控制导致验证失败?一个例子是与文本框负载的一种形式:用户点击按钮,我得到我的结果在验证摘要。所有罚款和花花公子。但我也希望让用户知道控制他们是通过改变各自的文本框的背景可以说,红了。
When the validators are in, is it possible to find out, through Jquery (ofcourse) which controls caused the validation to fail? An example would be a form with loads of text boxes: user clicks the button and I get my results in a validation summary. All fine and dandy. But I also want to let the users know which controls they are by changing the respective textbox background to lets say, red.
现在对于黑客将是我叫我自己的JS函数,用于检查验证(再次)中的所有文本框,然后更改CSS来无效问卷显示红色。不过,我本来以为肯定有一定的方式来识别哪些控件无法进行验证?
Now the hack for that would be that I call my own JS function that checks all the textboxes for validation (again) and then change the css to invalid ones to show red. But I would have thought there surely must be a way to identity which controls failed the validation?
任何有识之士?
推荐答案
(A)
是不可能的。 Page.IsValid
由服务器端验证设置和客户端不应该惹它。客户端验证不回来后,如果它失败无论如何,所以 Page.Validate()
是不是在这种情况下,即使调用。
(A)
is not possible. Page.IsValid
is set by server-side validation and the client should not mess with it. Client-side validation doesn't post back if it fails anyway, so Page.Validate()
isn't even called in that case.
借助 AJAX控件工具包达到(B)
通过重新绑定验证功能。您可以尝试类似如下:
The AJAX Control Toolkit achieves (B)
by rebinding the validation functions. You can try something like the following:
的 [免责声明:我不熟悉的jQuery(还),所以我会用纯JS。随意转换到相应的jQuery的成语。] 的
for (var i = 0; i < window.Page_Validators.length; ++i) {
var validator = window.Page_Validators[i];
validator.__old_evaluationfunction = validator.evaluationfunction;
validator.evaluationfunction = function(value) {
var element = validator.controltovalidate;
if (!validator.__old_evaluationfunction(value)) {
// Validation failed - turn `element` red, scream at the user, etc.
return false;
} else {
// Validation succeeded - restore `element` to its normal state.
return true;
}
};
}
这篇关于它控制触发Page.IsValid =假?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!