验证对象具有controltovalidate
字段保持该服务器控制(在CustomValidator
ControlToValidate
属性指定)的唯一ID。所以,你可以轻松地设置值回你的控制如下:
function trimAndSetBack(val, args) {
// val.controltovalidate will always hold unique id
// of the server control so document.getElementById will work always
ValidatorSetValue(val.controltovalidate, ValidatorTrim(eventArgs.Value));
}
function ValidatorSetValue(id, value) {
var control;
control = document.getElementById(id);
if (typeof (control.value) == "string" && (control.type != "radio" || control.checked == true)) {
control.value = value;
return true;
}
var i;
for (i = 0; i < control.childNodes.length; i++) {
if (ValidatorSetValue(control.childNodes[i], value)) {
return true;
}
}
return false;
}
ValidatorSetValue
是标准ValidatorGetValueRecursive
功能有点修改后的版本。如果您处理输入控件嵌套在其中的用户控件,则需要递归。