I am having a problem where my button click event is still firing even though my custom server-side validation is set to args.IsValid = false. I am debugging through the code and the validation is definitely being fired before the button click, and args.IsValid is definitely being set to false once the custom validation takes place, but it always makes its way to the button click event afterwards. Any ideas on why this is?
2 Answers
Not sure 100% of the particulars, but to prevent code from continuing, add to your button click event handler:
if (!Page.IsValid)
return;
That will prevent the code from executing.
1 Comment
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 b4 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