The error only occurs client-side and can be avoided by setting EnableClientScript=false on the validator. The error occurs because the ValidatorGetValueRecursive function (basically) returns the first non-empty value from an input element. When the text input is empty, it returns the value from the HiddenField with the selected index (-1 when empty).
I'd suggest setting the HiddenField to the empty string, rather than -1, when a value is not selected to avoid the issue.
The AJAX Control Toolkit 20.1.0
The installation method
Minimal steps to reproduce the bug
Add a validator control (e.g.
RegularExpressionValidator
) to aComboBox
. Attempt to submit the form, leaving theComboBox
empty.Actual result
Validation fails and the form is not submitted.
Expected result
The form would be submitted without error, as it would be if
ComboBox
were replaced withTextBox
.Browser(s) used
A site deployment method
Sample project: https://gist.github.com/kevinoid/6f3773ed5ea51e43b6cafed2da3f75e9
Discussion
The error only occurs client-side and can be avoided by setting
EnableClientScript=false
on the validator. The error occurs because theValidatorGetValueRecursive
function (basically) returns the first non-empty value from aninput
element. When the text input is empty, it returns the value from the HiddenField with the selected index (-1 when empty).I'd suggest setting the HiddenField to the empty string, rather than -1, when a value is not selected to avoid the issue.
Thanks for considering, Kevin