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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.