How to Stop a Client Side Event With a Validator
- 1). Open your programming software of choice and open the page that must contain the validator.
- 2). Drag-and-drop a CustomValidator control onto the page and set its ClientValidationFunction equal to "sampleFunction:"
<asp:CustomValidator id="CustomValidator1" runat="server"
OnServerValidate="TextValidate"
ControlToValidate="TextBox1"
ErrorMessage="Text must be 8 or more characters."
ClientValidationFunction="sampleFunction">
</asp:CustomValidator>
(See References 3) - 3). Write a "sampleFunction()" method to disable the target event, using JavaScript's native ".removeEventListener()" method:
<script type="text/javascript">
function sampleFunction(){
element.removeEventListner('click',functionToDisable);
}
</script>
The above code, for example, stops the client side event named "functionToDisable's" click event. - 4). Save your work. Open the Web page in an Internet browser to ensure it performs as expected.