It is a common requirement to validate different fields on an ASP.NET form based on different conditions, for instance, if user selects “Other” from a Drop Down List, then he/she will be required to type in something in a TextBox control. It can be done easily in code behind, but can we accomplish the same task at the client side? The answer is yes. We can use ASP.NET validation’s client API to conditionally enable/disable validators. Here is how:
First, let’s create a simple ASP.NET form as follows:
When “No” is selected from the radio button list, then a valid date is required to be entered in the first text box, otherwise, the text box is optional. If “Other” is selected from the occupation drop down list, then the second text box is required, otherwise, it is optional.
You can check the demo to see how it works.