asp.net required field validator for at least one textbox contains text

前端 未结 2 1225
温柔的废话
温柔的废话 2020-12-10 06:04

I have three textboxes on an asp.net webform, how/can I use a required field validator to ensure that at least one of them contains text?

2条回答
  •  攒了一身酷
    2020-12-10 06:56

    I would use a CustomFieldValidator like this:

    
    

    and then in your codebehind you have:

    protected void MyCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
    {
         if (/* one of three textboxes has text*/)
             args.IsValid = true;
         else
             args.IsValid = false;
    }
    

    You can also add a Client-side component to this validation, and make it sexy by extending it with AJAX toolkit's ValidatorCalloutExtender control.

提交回复
热议问题