views:

15

answers:

0

I am using this code to validate the text box which is an amount column in a dynamic grid.

<asp:TemplateField HeaderText="Amount">
    <ItemTemplate>
        <asp:TextBox ID="txtAmount" Text='<%# Bind("SD_AMOUNT") %>' runat="server" MaxLength="16"
            AutoPostBack="true" Style="text-align: right" OnTextChanged="txtAmount_TextChanged"></asp:TextBox>
    </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
    <ItemTemplate>
        <asp:RegularExpressionValidator ID="regVal1" runat="server" ControlToValidate="txtAmount"
            ErrorMessage="Format(3int,5deci)" ValidationExpression="^[1-9]\d{0,12}(\.\d{1,2})?%?$"
            ValidationGroup="req" Display="None" SetFocusOnError="true">
        </asp:RegularExpressionValidator>
    </ItemTemplate>
</asp:TemplateField>

My issue is that it is not validating properly. I have used some code in the textbox's changed event. How to run the validation code when the user uses the Tab key to navigate away from the textbox?