Possible to fire asp.net validation from jQuery?

Posted by Abe Miessler on Stack Overflow See other posts from Stack Overflow or by Abe Miessler
Published on 2010-04-07T17:21:27Z Indexed on 2010/04/07 17:23 UTC
Read the original article Hit count: 215

Filed under:
|
|

I have a form with several text boxes on it. I only want to accept floats, but it is likely that users will enter a dollar sign. I'm using the following code to remove dollar signs and validate the content:

jQuery:

            $("#<%= tb.ClientID %>").change(function() {
                var ctrl = $("#<%= tb.ClientID %>");
                ctrl.val(ctrl.val().replace('$',''))
            });

asp.net validation:

<asp:CompareValidator ID="CompareValidator4" runat="server" Type="Double" ControlToValidate="tb" Operator="DataTypeCheck" ValidationGroup="vld_Page" ErrorMessage="Some error" />

My problem is that when someone enters a dollar sign in the TextBox "tb" and changes focus the validation happens first and THEN the jQuery removes the dollar sign. Is it possible to have the jQuery run first or to force the validation to run again after the jQuery executes?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about validation