I'm trying to create a method that will custom validate any TextBox control passed to it.
Here's what I've got so far:
A Custom Validator
protected void CustomValidatorDelLN_ServerValidate(object sender, ServerValidateEventArgs args)
{
CustomValidator ThisValidator = sender as CustomValidator;
TextBox MyBox = FindControl(ThisValidator.ControlToValidate) as TextBox;
args.IsValid = isValid(MyBox);
}
Validation Method
protected bool isValid(System.Web.UI.WebControls.TextBox MyBox)
{
bool is_valid = MyBox.Text != "";
MyBox.BackColor = is_valid ? System.Drawing.Color.White : System.Drawing.Color.LightPink;
return is_valid;
}
The code compiles OK but I get a
NullReferenceException was unhandled by user code
on
bool is_valid = MyBox.Text != "";
When I run the validation.
I know I'm close (well I think I am) but where am I going wrong?