& # 39; controltovalidate& # 39;IE8出现错误

本文关键字:错误 controltovalidate IE8 | 更新日期: 2023-09-27 17:53:18

我得到一个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错误

消息:'controltovalidate'是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);
    }

我注意到doesUserExist函数因为某种原因被调用了两次,有人能从这段代码中告诉为什么吗?

& # 39; controltovalidate& # 39;IE8出现错误

显示UpdatePanel正在引起第二个ajax调用,并导致IE抛出JS错误。在其他浏览器中工作良好,但不是IE7/8!

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