Note that there are some explanatory texts on larger screens.

plurals
  1. POAsp.net CustomValidator client validation not firing when response comes from jQuery AJAX
    primarykey
    data
    text
    <p>I'm trying to validate an email textbox on blur using jQuery AJAX with an ASP.net webforms CustomValidator.</p> <pre><code>&lt;asp:TextBox ID="Email" runat="server" ClientIDMode="Static"&gt; &lt;asp:CustomValidator ID="EmailRegisteredValidatation" ControlToValidate="Email" runat="server" ValidationGroup="RegisterUserValidationGroup" ClientValidationFunction="CheckEmailRegistration" ErrorMessage="Email Already Registered"&gt;&lt;/asp:CustomValidator&gt; function CheckEmailRegistration(sender, args) { $.post("/api/CheckEmailRegistration/", { Email: $("#Email").val() }) .done(function (data) { args.IsValid = data; }); } </code></pre> <p>That script isn't working. It doesn't change the validation status. I know for sure the returned data is either true or false. But I'm guessing the delay of the AJAX result is causing a problem.</p> <p>This works ok:</p> <pre><code> function CheckEmailRegistration(sender, args) args.IsValid = false; } </code></pre> <p>This also doesn't work:</p> <pre><code>function CheckEmailRegistration(sender, args) { $.post("/api/CheckEmailRegistration/", { Email: $("#Email").val() }) .done(function (data) { args.IsValid = false; //even hardcoded doesn't work }); } </code></pre> <p>Outside of the scope also doesn't work:</p> <pre><code> function CheckEmailRegistration(sender, args) { var _value; $.post("/api/CheckEmailRegistration/", { Email: $("#Email").val() }) .done(function (data) { _value = data; } }); args.IsValid = _value; } </code></pre> <p>Any ideas?</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload