0

Hello there..

I have a custom validator for my text boxes. the code is as below..
Expand|Select|Wrap|Line Numbers

<asp:CustomValidator ID="CustomValidator3" runat="server" ControlToValidate="text1" 
                                                    ErrorMessage="Please enter text1" 
                                                    ClientValidationFunction="ClientValidate3" ValidateEmptyText="true" ValidationGroup="Submit" 
                                                    onservervalidate="CustomValidator3_ServerValidate" Display="Dynamic" SetFocusOnError="false">*</asp:CustomValidator>
function ClientValidate3(sender, args) {
            var txt1 = document.getElementById("<%= text1.ClientID %>");
            var txt2 = document.getElementById("<%= text2.ClientID %>");
              if ((txt1.value == "" && txt2.value != ""))
            {
                args.IsValid = false;
            } else {
                args.IsValid = true;
            }
            if ((txt1.value == "" && txt2.value != ""))        
            document.getElementById("<%= text1.ClientID%>").focus();
        }
protected void CustomValidator3_ServerValidate(object source, ServerValidateEventArgs args)
        {
           if ((text1.Text == "" && text2.Text != ""))
            {
                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }

now the problem is ..when I do not enter text in the other text box, the custom validator immediately gives me the error message but this error message does not clear out when the text is filled in the box and the cursor or focus moves away from it. This would confuse the user a lot as he/she can still see the error message even after the text box is filled. is it how the custom validator behaves or is there something that I can change in my code for this to happen..
can somebody please tell me..thank you

2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by user1980
0

Use the leave event of textbox
there you check for if it is filled or not
that might solve ur problem

0

thank you for the response..but I am not sure I follow you....can you please be more clear..thank you

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.