Trying to apply a custom client-side validation of a TextBox which is required to have a value. The reasson why I make a CustomValidation is because it is only required to have a value if it is visible (through some other
display:block/none another place on the page).
The client-side script, however, only triggers when I have already entered text into the field. The
javascript method, which I call is simply an alert, so it should be called no matter what! The CustomValidation control is added dynamically and defined as follows...
Code:
CustomValidator val = new CustomValidator();
val.ID = "validator:titleLink";
val.EnableClientScript = true;
val.ClientValidationFunction = "validateTextIfVisible";
val.ServerValidate += new ServerValidateEventHandler(val_ServerValidate);
val.ControlToValidate = "titleLink";
val.Display = ValidatorDisplay.Dynamic;
val.ErrorMessage = "Error...";
That is, when I have just loaded the form and click submit the validation will not fire, but after I have entered data it will, Pretty odd. I am rather new to the CustomValidation so...
Why can this be?
Thanks, Jacob.