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. it only fires if i attempt to write text in the txtTelephone textbox. How do i make sure it validates on postback like the rest of the validation controls?
<asp:CustomValidator ID="CustomValidator1" ControlToValidate="txtTelephone" runat="server" ValidationGroup="pnlForm"
开发者_JAVA技巧 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"
精彩评论