IE8中的“controltovalidate”错误

时间:2013-01-14 21:35:35

标签: c# jquery ajax internet-explorer

我收到了JavaScript错误(当然只在IE中),我无法弄清楚原因。我以为它是一个尾随的逗号或其他东西,但我找不到。我希望我能忽略一些东西,也许你们其中一个人可以看到我错过的东西。

我的控件和自定义验证器:

<asp:TextBox runat="server" ID="txtName" MaxLength="100" CssClass="styled" Columns="50" />
                                <asp:CustomValidator runat="server" ID="cvName" ErrorMessage="Enter a valid contact name or email address" ControlToValidate="txtName" Display="None" ValidationGroup="PlatformContact" ClientValidationFunction="doesUserExist" />
                                <asp:ValidatorCalloutExtender ID="vceName" runat="server" TargetControlID="cvName" WarningIconImageUrl="~/img/icons/ic_asterisk.gif" CssClass="validatorStyled" PopupPosition="Right" CloseImageUrl="~/img/icons/ic_x_close_orange.png" />                                    
                                <asp:RequiredFieldValidator runat="server" ID="valName" ErrorMessage="Enter a contact name or email address" ControlToValidate="txtName" Display="None" ValidationGroup="PlatformContact" />
                                <asp:ValidatorCalloutExtender ID="vceNameRequired" runat="server" TargetControlID="valName" WarningIconImageUrl="~/img/icons/ic_asterisk.gif" CssClass="validatorStyled" PopupPosition="Right" CloseImageUrl="~/img/icons/ic_x_close_orange.png" />

这是我正在使用的JavaScript / jQuery:

<script language="javascript" type="text/javascript">
    var userExists = true;

    function doesUserExist(source, args) {
        var txtName = $('#<%= txtName.ClientID %>').val();
        $.ajaxSetup({ cache: false });
        $.ajax({
            type: "POST",
            contentType: "application/json",
            data: "{name:'" + txtName + "'}",
            url: "ManageMyContacts.aspx/DoesUserExist",
            dataType: "json",
            success: function (result) {
                userExists = result.d;
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //Something bad happened,redirect to login page
                window.location.href = '<%= ResolveUrl("~/Default.aspx") %>';
            }
        });
        args.IsValid = userExists;
    }
</script>

非常感谢任何见解。

编辑:JavaScript错误

  

消息:&#39; controltovalidate&#39;是null或不是对象

这是WebMethod I用户检查用户名(在后面的代码中)

[WebMethod(EnableSession = true)]
    public static bool DoesUserExist(string name)
    {
        ManageMyContactsService service = new ManageMyContactsService();
        int index = name.IndexOf("[") + 1;
        if (index > 0)
        {
            string email = name.Substring(index, name.Length - (index + 1));
            return service.DoesUserExist(email);
        }
        else if (name.IndexOf("@") == -1)
            return false;
        else
            return service.DoesUserExist(name);
    }

我注意到doUserExist函数由于某种原因被调用了两次,有人可以从这段代码中说出原因吗?

1 个答案:

答案 0 :(得分:0)

似乎UpdatePanel导致第二次ajax调用并导致IE抛出JS错误。在其他浏览器中工作得很好但不是IE7 / 8!

希望帮助有类似问题的人。