I have a registration form with several validator controls. I am checingk the username availability via AJAX (using jQuery, NOT an UpdatePanel). If the username is taken, I would like to make the page invalid like the other ASP.NET validators do from my JavaScript function. Is this possible? Examples?
Here is my current functionality:
// In head...
<script type="text/javascript">
$(document).ready(function () {
$('#<%= username.ClientID %>').blur(function () {
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: 'MyService.asmx/CheckAvailability',
dataType: 'json',
data: '{ "username": "' + username + '" }',
success: function (response) {
// stuff
// If username is taken, invalidate
}, error: function () { /* stuff */ }
});
});
});
</script>
// The markup...
<dl><dt>Username</dt>
<dd>
<asp:textbox id="username" runat="server" />
<asp:requiredfieldvalidator id="usernameRequiredValidator" runat="server"
controltovalidate="username"
errormessage="Required"
display="Dynamic" />
<span id="avail_response"></span>
<!-- More stuff... -->