Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

How to ensure the Validator keeps sending back an error message from an ASP.NET application using C# with VS2010?

I am developing an ASP.NET application in C# using VS2010.

I use a gridview and within the grid, I validate an input date field titled "txtchkDt".
If the user inputs a date into this field in the format "CCYY/MM/DD", the RegularExpressionValidator sends back the error message: "Date must be in the format of MM/DD/YYYY"
After the user inputs this value, I have an link in the last column that the user clicks on to update the record.
So if the user clicks on the link for the first time, the error message is generated.
However, if the user doesn't change the date entered in the format "CCYY/MM/DD and clicks on the link to update a 2nd time,
the Validator doesn't resend the error message and the application jumps into the event, gridview_RowUpdating.

Do you know how I can ensure that the application will keep sending back the error message from the Validator until the user enters the date in the format "MM/DD/YYYY"?


                    <EditItemTemplate>                                        
                               <asp:TextBox ID="txtchkDt"  runat="server" Text='<%# Eval("chkDt") %>'></asp:TextBox>
                    <asp:CompareValidator ID="DateValidator1" runat="server" Operator="DataTypeCheck"
                    Type="Date" ControlToValidate="txtchkDt" ErrorMessage="Please enter a valid start
                    date mm/dd/yyyy" />  
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtchkDt" Display="Dynamic" ErrorMessage="Date is required" ValidationGroup="AllValidators">*</asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtchkDt" Display="Dynamic" ErrorMessage="Date must be in the format of MM/DD/YYYY" ValidationGroup="AllValidators" ValidationExpression="^(0?[1-9]|1[0-2])\/(0?[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}" ForeColor="#FF0066"></asp:RegularExpressionValidator>                        
                    </EditItemTemplate>
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial