Odd Custom Validation Problem
-
I am trying to use custom validation in order to validate certain controls when different radio buttons are checked. There are two radio buttons - when the first one is checked I need to validate location_code and when the second is checked I am going to have to validate four separate textboxes. When the first one is checked, my custom validation is working fine: And here is my javascript function: function location_code(source, args) { if(document.Form1.officelocation[0].checked) { if(args.Value == "select") args.IsValid = false; else args.IsValid = true; } else args.IsValid = true; return; } However, my second custom validator appears to be doing apsolutely nothing. Even when I use the following javascript, nothing happens: function address1(source, args) { alert("hello address"); return; } Does anyone know why my second validator would not be working when it is set up like the first one (which is working)? Does anyone have any other ideas I could possibly use to validate in my situation? Thanks, Scott Stocker
-
I am trying to use custom validation in order to validate certain controls when different radio buttons are checked. There are two radio buttons - when the first one is checked I need to validate location_code and when the second is checked I am going to have to validate four separate textboxes. When the first one is checked, my custom validation is working fine: And here is my javascript function: function location_code(source, args) { if(document.Form1.officelocation[0].checked) { if(args.Value == "select") args.IsValid = false; else args.IsValid = true; } else args.IsValid = true; return; } However, my second custom validator appears to be doing apsolutely nothing. Even when I use the following javascript, nothing happens: function address1(source, args) { alert("hello address"); return; } Does anyone know why my second validator would not be working when it is set up like the first one (which is working)? Does anyone have any other ideas I could possibly use to validate in my situation? Thanks, Scott Stocker
Hi there, If the textbox validated by the second custom validator is empty, then the client side function
address1
never gets called as it is considered true by default. For more information, you can see CustomValidator Class[^] So in this case, you can use RequiredField Validator instead, however, you are required to provide some script to enable/disable the RequiredField validator depending on the status of the radio buttons as you may not want it to run when the first radio button is selected. Another idea is to develop your own custom validator which accepts an empty textbox to validate. For more information, you can see Developing a Validator Control[^] Just some ideas.