It seems that ASP.NET validators do not validate hidden fields. I get messages like this:
Control ‘hiddenField’ referenced by the ControlToValidate property of ‘hiddenFieldValidator’ cannot be validated.
I have an <asp:HiddenField> in my page which gets filled client side with some value. I need this to be present once on the server so I added a RequiredFieldValidator to it.
And it does not work!
As I see it, as a workaround, I can:
1. use a custom validator and not tie it to the hidden field, just call a method on OnServerValidate;
2. Use a <asp:TextBox> with a CSS style display:none and it should work.
But I want to make sure I am not missing something here. Is it possible or not to validate a hidden field in the same way as the other text fields? O maybe a third, more elegant option?
TIA!
Just as the exception message you’re getting says, it seems
HiddenFieldcontrols can’t be targeted by the standard validation controls directly. I would go with theCustomValidatorworkaround.