为什么customvalidator控件不会触发clientide validaation函数? [英] Why customvalidator control does not fire clientside validaation function?

查看:83
本文介绍了为什么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 = < span class =code-keyword> 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


这篇关于为什么customvalidator控件不会触发clientide validaation函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆