Reputation: 411
Hi I have a textbox in a RadGrid which is required only when another control which is a dropdownbox has a certain value.
I think the best way to make use of a CustomValidator here but you need a RequiredFieldValidator to make the Custom one fire.
However this is not going to work for me because the field is only required when the dropdownbox has a particular value. If it doesn't it doesn't matter if nothing is in the Textbox
Any suggestions?
Upvotes: 0
Views: 1296
Reputation: 11
set the ValidateEmptyText="yes" for the CustomValidator. then it will fire even if the value is blank.
Upvotes: 1
Reputation: 73564
Just an idea....
Set up the validators (the custom one and the requiredfield one) and have it disabled, then in the drop-down's SelectedIndexChanged event, check for the value you're looking for and enable the validators when required. Of course, that's a server-side solution requiring a postback, but it can be done in Javascript or via Ajax as well.
Upvotes: 1
Reputation: 3216
You could make use of the .NET client side validation API and turn on/off the validator depedant on the value in the drop down box.
ValidatorEnable(val, enable) is used to turn on or off a particular validator (where val is the validator and enable is a boolean indicating wheter to enable or disable it.
http://msdn.microsoft.com/en-us/library/aa479045.aspx
Upvotes: 1