Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
ASP.NET
<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>


JavaScript
<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>


What I have tried:

i've included validateEmptyField =true, but no desired output
Posted
Updated 14-Mar-17 19:46pm
v2
Comments
F-ES Sitecore 14-Mar-17 9:56am    
It doesn't work because your code is wrong so you need to fix it. If you want help fixing the code then it might be good if you posted it for others to see.
Member 12677894 15-Mar-17 1:47am    
added the code, any solution??
Sunasara Imdadhusen 15-Mar-17 9:10am    
are you sure the function "myfunction" is not calling? or it is calling but not validating?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900