【问题标题】:ValidatorEnable not workingValidatorEnable 不起作用
【发布时间】:2014-07-04 07:23:57
【问题描述】:

我的代码如下

<asp:DropDownList ID="ddlFilter" runat="server" onchange="ShowHideSearchTextBox(this)">
                                <asp:ListItem Value="0">--Select--</asp:ListItem>
                                <asp:ListItem Value="customer_name">Customer Name</asp:ListItem>
                                <asp:ListItem Value="order_number">Order Number</asp:ListItem>
                                <asp:ListItem Value="Pending">Dispatch Pending</asp:ListItem>
                                <asp:ListItem Value="Done">Dispatch Done</asp:ListItem>
                            </asp:DropDownList>

<script type="text/javascript">
        function ShowHideSearchTextBox(me) {
            var searchBox = document.getElementById("searchBox");
            var validator = document.getElementById(" <%= RequiredFieldValidator1.ClientID%> ");
            if (me.value == "Pending" || me.value == "Done") {
                ValidatorEnable(validator, false);
                searchBox.style.display = "none";
            }
            else {
                ValidatorEnable(validator, true);
                searchBox.style.display = "block";
            }
        }
    </script>

无论我在下拉菜单中选择什么值,我的验证器始终处于活动状态。我错过了什么?

编辑

validator 的值即将到来null

【问题讨论】:

    标签: javascript asp.net validation


    【解决方案1】:

    您好,我假设您的验证器已正确实现,因此问题在于您如何在 javascript 中访问验证器:

    var validator = document.getElementById(" <%= RequiredFieldValidator1.ClientID%> ");
    

    改成:

    var validator = document.getElementById("<%= RequiredFieldValidator1.ClientID %>");
    

    删除引号中多余的空格应该可以解决问题,因为getElementById 不会为您删除空格。

    在上面测试了您的代码(使用有效的验证器)并且更改解决了问题。

    【讨论】:

      猜你喜欢
      • 2013-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多