Custom validator only fired on first button click?
I have a custom validator and some other validators on the page. But whenever I click the submit button for first time it only fires the custom validator and when I click the button for second time it's validating rest of the validators. Please let me know if you have any solu开发者_如何转开发tion.
Thanks
Check your Page_Load
to make sure you are not hiding or enabling something after the second call. I had a similar problem before and it confused the heck out of me until I realized I was manipulating a Panel
in the Page_Load
that contained the validator.
Other than that, you would need to post code (your Page_Load
and Click
event).
On Client Side when
OnClientClick="return SomeCustomClientCode();"
Is called, asp.net validators e.g required field validators are disabled and it does not gets listed in validators collection and does not validate the field validated by this validator and page post backs if custom validation passes.
To avoid this explicitly enable asp.net validators in Custom validation code or else where so that it gets activated before page postback or in the begiining of custom validation as follows:
ValidatorEnable(document.getElementById('<%=rfvDDLStatus.ClientID%>'), true);
rfvDDLStatus ==> required field validator
which was not firing.. ValidatorEnable ==> Client API
to enable asp.net validator
精彩评论