ASP.NET Web-forms custom validator not firing
Try removing ControlToValidate
entirely. Though I've never tried to validate a file upload before, most validators won't fire (except RequiredField
) if the contents are empty. Taking off the control to validate should make it fire always for that group.
EDIT (Chevex) - The ControlToValidate
was the issue, but not because it was broken. By default it will not fire on controls with no value, as stated above. Setting the custom validator control property ValidateEmptyText="true"
solves the issue. Sad that I had to start this giant question just to find that, but now we know! :)
You need to specify the same ValidationGroup="" to your button, and to your validators
For me this occurred when the validator and its related input were inside a control that had visible="false"
set in the control mark up. This was causing the CustomValidator to inherit the Visible = false
property and preventing validation from firing. On a normal page load I wasn't making the controls visible until later in the page lifecycle.
In any case if you set a breakpoint on the Page.Validate()
method you can inspect the Page.Validators
collection and see if a similar thing might be happening to you.