views:

360

answers:

1

I want to do exactly the same thing that in this question : http://stackoverflow.com/questions/1249709/jquery-validation-remote-validation-not-working

The only thing that change is that I'm using Asp.Net WebForm instead of Asp.Net MVC. So, the solution proposed in this post doesn't work for me...

UPDATE

From Jeff comment, here's my new try:

$("#mainForm").validate(
{
    rules:
    {
        UserName:
        {
            required: true
           ,remote: "IsValidField"
        }
     ,messages:
    {
        UserName:
        {
            remote: "UserName has already been choosen. Please choose another one"
        }
    }

 }

c#

public String IsValidField()
{
    String the_field = Request["Field_To_Test"];
    JavaScriptSerializer serializer = new JavaScriptSerializer();

    if (the_field == another_value)
        return serializer.Serialize(true);
    else
        return serializer.Serialize(true);
}

If I put a breakpoint the method is never call...

+1  A: 

Regardless of webforms or MVC, your page method still has to return a JSON object. So the solution in that post should work fine in a ASP.NET Webforms project.

Jeff Siver
Can you provide me an example of how I can return a JSON object because I didn't find this namespace. I didn't find the ActionResult namespace either. So, I don't understand how I can use the proposed solution.
Melursus
You can use Sys.Serialization.JavaScriptSerializer to create the json object.
Jeff Siver