开发者

customvalidator not firing client side script on postback

开发者 https://www.devze.com 2023-03-28 15:38 出处:网络
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

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"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号