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: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>
What I have tried:
i've included validateEmptyField =true, but no desired output