简体   繁体   English

IE8中的“ ​​controltovalidate”错误

[英]'controltovalidate' error in IE8

I'm getting a JavaScript error (in IE only of course) and I can't figure out why. 我收到JavaScript错误(当然,仅在IE中),我不知道为什么。 I assumed it was a trailing comma or something but I can't find one. 我以为是逗号或其他东西,但找不到。 I'm hoping I'm overlooking something and maybe one of you can see what I missed. 我希望我能忽略一些东西,也许你们中的一个可以看到我错过的东西。

My control and custom validator: 我的控件和自定义验证器:

<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" />

And here is the JavaScript/jQuery I am using: 这是我正在使用的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>

Any insight is greatly appreciated. 非常感谢任何见解。

EDIT: JavaScript error 编辑:JavaScript错误

Message: 'controltovalidate' is null or not an object 消息:“ controltovalidate”为空或不是对象

Here is the WebMethod I user to check for the user name (in the code behind) 这是我要检查用户名的WebMethod(在后面的代码中)

[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);
    }

I noticed the doesUserExist function gets called twice for some reason, can anyone tell why from this code? 我注意到dosUserExist函数由于某种原因被两次调用,有人可以从此代码中看出原因吗?

It appears an UpdatePanel was causing the second ajax call and was causing IE to throw a JS error. 似乎UpdatePanel导致了第二个ajax调用,并导致IE抛出JS错误。 Worked fine in the other browsers but not IE7/8! 在其他浏览器上工作正常,但在IE7 / 8上却不行!

Hope that helps someone with a similar issue. 希望能对遇到类似问题的人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM