本文介绍了Asp.Net WebForm JQuery远程验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做与此问题完全相同的事情: Jquery验证远程验证不起作用

I want to do exactly the same thing that in this question : Jquery Validation remote validation not working

唯一的变化是我使用的是Asp.Net WebForm而不是Asp.Net MVC.因此,本文中提出的解决方案对我不起作用...

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...

根据Jeff的评论,这是我的新尝试:

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...

推荐答案

无论Webforms还是MVC,您的page方法仍然必须返回JSON对象.因此,该文章中的解决方案在ASP.NET Webforms项目中应该可以正常工作.

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.

这篇关于Asp.Net WebForm JQuery远程验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:49