I am using jQuery remote validation with asp.net codebehind and webservice, now the remote function is hitting the server fine and I am returning True or false JSON response but what is happening is the following:
The first time I hit the Login button with intentional empty field I get an error message both on client side and server side, fine but if I fill the field and try to hit the login button the Remote function is working fine but not client side and the error message is not going even though the field is filled.
I have tried many searches on net with no luck, I would deeply appreciate it if someone could help on this.
Here is my code:
$("#Login").click(function () {
$("#form1").validate(
// This prevents validation from running on every
// form submission by default.
// onsubmit: false
{ rules: { Email: { required: true,
remote: {
type: "POST",
url: "WebForm1.aspx/IsValid",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{'username':'" + function () {
return $("#UserName").val();
} + "'}", success: function (msg) {
result = (msg == '1') ? true : false;
// alert(msg.d);
}
}
}
}
}
);
var isValid = $("#form1").valid();
alert(isValid);
});
server side code
public static Boolean IsValid()
{
return true;
}