[英]customvalidator not firing client side script on postback
I have created a custom validator (below) that checks two textboxes to make sure at least one of them has a value, for some reason this validation will not fire when the user clicks the submit button for the form like the rest of the validation in the validation group.我创建了一个自定义验证器(如下),它检查两个文本框以确保其中至少一个具有值,由于某种原因,当用户单击表单的提交按钮时,此验证不会触发,例如验证的 rest验证组。 it only fires if i attempt to write text in the txtTelephone textbox.
只有当我尝试在 txtTelephone 文本框中写入文本时它才会触发。 How do i make sure it validates on postback like the rest of the validation controls?
我如何确保它在回发时进行验证,例如验证控件的 rest?
<asp:CustomValidator ID="CustomValidator1" ControlToValidate="txtTelephone" runat="server" ValidationGroup="pnlForm"
ErrorMessage="You must provide a contact telephone number" ClientValidationFunction="validatetele" Display="Dynamic" EnableViewState="false"></asp:CustomValidator>
<script type="text/javascript">
function validatetele(sender, args) {
var tbone = document.getElementById('<%=txtTelephone.ClientID %>');
var tbtwo = document.getElementById('<%=txtMobile.ClientID %>');
if (tbone.value == '') {
if (tbtwo.value == '') {
args.IsValid = false;
} else {
args.IsValid = true;
}
} else {
args.IsValid = true;
}
}
</script>
You need ValidateEmptyText="True"
你需要
ValidateEmptyText="True"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.