问题描述
我有一个验证电话号码为几个不同的电话编号方案一的CustomValidator。该客户端JavaScript看起来像这样:
validatePhoneNumber(发件人,参数){
cleanNumber = args.Value.replace(/ \\ D /,);
国家= $(#+ CountryID)获得(0).value的;
开关(国家){
案北美:
args.IsValid = validateNAPhoneNumber(cleanNumber);
如果(args.IsValid!)sender.errormessage =*不是NA电话号码;
打破;
案UK:
args.IsValid = validateUKPhoneNumber(cleanumber);
如果(args.IsValid!)sender.errormessage =*不是英国的电话号码;
打破;
...
}
}
实际的检验发生不当,以及具有的CustomValidator在任何时候都正确的IsValid属性。该sender.errormessage,但是,似乎被改写刚过此函数调用它的默认值。我如何更改errormessage的价值,并使其棒?
函数出生日期(来源参数){ VAR dtcDOB =的document.getElementById('<%= dtcDOB.ClientID%GT;'); VAR DOB =新的日期(dtcDOB.value);
VAR currDate =新的日期(); 如果(dtcDOB.value ==){
args.IsValid = FALSE;
source.textContent =提供DOB。
返回;
} args.IsValid = TRUE;
}
试 source.textContent =你的错误消息
。
它为我工作。
I have a CustomValidator that is validating a telephone number for several different telephone numbering schemes. The client-side javascript looks like this:
validatePhoneNumber(sender, args) {
cleanNumber = args.Value.replace(/\D/, "");
country = $("#" + CountryID).get(0).value;
switch (country) {
case "North America":
args.IsValid = validateNAPhoneNumber(cleanNumber);
if (!args.IsValid) sender.errormessage = "* Not a NA Phone #";
break;
case "UK":
args.IsValid = validateUKPhoneNumber(cleanumber);
if (!args.IsValid) sender.errormessage = "* Not a UK Phone #";
break;
...
}
}
The actual validation takes place properly, and the CustomValidator has the correct IsValid property at all times. The sender.errormessage, however, seems to be rewritten just after this function call to it's default value. How can I change the errormessage value, and make it "stick"?
function dateofbirth(source, args) {
var dtcDOB = document.getElementById('<%= dtcDOB.ClientID %>');
var dob = new Date(dtcDOB.value);
var currDate = new Date();
if (dtcDOB.value == "") {
args.IsValid = false;
source.textContent = "Provide DOB.";
return;
}
args.IsValid = true;
}
try source.textContent = "your err msg"
.It worked for me.
这篇关于我怎样才能重写客户端上的CustomValidator控件中的ErrorMessage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!