I need to validate TextBox based on Value selected in DropDownList controls. I have asp:TextBox and asp:DropDownList controls.
If user selects Yes option from the first dropdown he must type value in text box. How can I validate second box? Thanks for help.
The simplest approach is to set the DropDownList’s
AutoPostBackproperty totrueand handle it’sSelectedIndexChangedevent. Then you can Enable/Disable the validator there.Another approach is to use a
CustomValidator. This validator is not dependent on a single control. You must write the validation rules on your own. For example the ClientValidationFunction:Remember to always implement a OnServerValidate because you should not rely on javascript only(can be disabled). This is easy:
VB.NET