I use the JQuery Validation plugin to validate a form (http://docs.jquery.com/Plugins/Validation/)
For example, I can validate an email in a form.
What I would like to do is to validate if the username chosen already exists. So, I need to call a server method that query the database. How can I do that ?
UPDATE
From balexandre answer, I try the following :
$.validator.addMethod("userName",
function(value, element)
{
$.get
(
"CheckUser.aspx?User=" + value,
function(data)
{
if (data == "True")
{
return false;
}
else if (data == "False")
{
return true;
}
else
{
alert(data);
}
}
);
},
"User already exists");
$(document).ready
(
function()
{
$("#aspnetForm").validate
(
{
rules:
{
<%=txtUserName.UniqueID %>:
{
required: true,
email: true,
userName: true
}
}
}
);
}
);
In the Response, I write a boolean (True of False) instead of 1 ou 0.
I know that my validation function is call. The problem is that it's always show the error message even if the user doesn't exists. I try to put an alert message before the return true to see if it's reach, and it is. So I don't get, why it's doesn't work...