Only validate controls if a value is present in first control
Posted on 2011-05-08
I have a form that contains 4 rows of controls, contained in a html table:
txtName1 ddlRelationShip1 ddlYearsLicensed1 ddlMariedYN1
txtName2 ddlRelationShip2 ddlYearsLicensed2 ddlMariedYN2
txtName3 ddlRelationShip3 ddlYearsLicensed3 ddlMariedYN3
txtName4 ddlRelationShip4 ddlYearsLicensed4 ddlMariedYN4
If a name is entered into a txtName textbox, then the remaining three fields are also required. For example, if the user fills in txtName1, then ddlRelationShip1, ddlYearsLicensed1, ddlMariedYN1 fields are also required.
The challenge here is, I don’t want to fire off validation on any rows of controls if the txtNameX contains no entry. In other words, all fields are required but only if the txtNameX contains data.
How can I build validation on this form so that validation is only active on those rows of controls where a name is entered into the name field (txtNameX) ?
Coded samples please. Thank you.