为什么customvalidator控件不会触发clientide validaation函数?

问题描述:

我有一个数据网格,一列是文本框,如果用户试图输入任何空格,它不应该允许,因此我为该文本框添加了一个customvalidator并编写了一个javascript函数来检测任何白色spcaces

但是,客户端javascript函数没有解雇



我正在使用.net4及其正在发生的asp.net4网络应用程序

i've a datagrid, one column is of textboxes, if the user tries to enter any white spaces, it shouldn't allow,hence ive added a customvalidator for that textbox and wrote a javascript function to detect any white spcaces
but, client side javascript function is not firing

i'm using .net4 and its happening asp.net4 web application

<pre></asp:TemplateColumn>
												<asp:TemplateColumn SortExpression="Qty" HeaderText="On Hand Qty">
													<HeaderStyle HorizontalAlign="center" VerticalAlign="Middle"></HeaderStyle>
													<ItemStyle HorizontalAlign="center" VerticalAlign="Middle"></ItemStyle>
													<ItemTemplate>
														<asp:TextBox width="50px" ID="lblOnHandQty" Runat="server" maxlength="8" Text='<%# DataBinder.Eval ( Container.DataItem, "Qty" ) %>'>
														</asp:TextBox>
                                                        <%-- <asp:RegularExpressionValidator runat="server" ID="regex2" ControlToValidate="lblOnHandQty" ValidationExpression="^[0-9]+$" ErrorMessage="qty Can only be positive number"></asp:RegularExpressionValidator>--%>
                                                         <asp:CustomValidator ID="CustomValidator2"  runat="server" ErrorMessage="CustomValidator" ValidateEmptyText="true" ClientValidationFunction="myfunction" EnableClientScript="true" ControlToValidate="lblOnHandQty"></asp:CustomValidator>
                                                    </ItemTemplate>
												</asp:TemplateColumn>







<pre><script type="text/javascript" language="javascript">
    function myfunction(source, arguments) {
        var patt = new RegExp(" ");
        var result = patt.test(arguments.value);
        if (result) {
            arguments.IsValid = true;
        }
        else {
            arguments.IsValid = false;
        }

    }
  </script>





什么我试过了:



我已经包含了validateEmptyField = true,但没有想要的输出



What I have tried:

i've included validateEmptyField =true, but no desired output

ErrorMessage =qty只能为正数>< / asp:RegularExpressionValidator> - %>
< asp:CustomValidator ID = CustomValidator2 runat = server ErrorMessage = CustomValidator ValidateEmptyText = true ClientValidationFunction = myfunction EnableClientScript = true ControlToValidate = lblOnHandQty > < / asp:CustomValidator >
< / ItemTemplate >
< / asp:TemplateColumn >
" ErrorMessage="qty Can only be positive number"></asp:RegularExpressionValidator>--%> <asp:CustomValidator ID="CustomValidator2" runat="server" ErrorMessage="CustomValidator" ValidateEmptyText="true" ClientValidationFunction="myfunction" EnableClientScript="true" ControlToValidate="lblOnHandQty"></asp:CustomValidator> </ItemTemplate> </asp:TemplateColumn>







<pre><script type="text/javascript" language="javascript">
    function myfunction(source, arguments) {
        var patt = new RegExp(" ");
        var result = patt.test(arguments.value);
        if (result) {
            arguments.IsValid = true;
        }
        else {
            arguments.IsValid = false;
        }

    }
  </script>





什么我试过了:



我已经包含validateEmptyField = true,但没有所需的输出



What I have tried:

i've included validateEmptyField =true, but no desired output