Link to home
Start Free TrialLog in
Avatar of dyarosh
dyarosh

asked on

RegularExpressionValidator Error Message doesn't show up in the ValidationSummary in ASP.NET

I have an ASP.Net page that has a date field on it.  I have 2 validation controls on the date field: RequiredFieldValidator and RegularExpressionValidator.  If I click on my Retrieve button without entering a date I get the Hire Date Required message from the RequiredFieldValidator in the ValidationSummary.

If I enter an invalid date in the date field and tab away, I only get the * and don't get the message in the ValidationSummary.  I've verified that I've used the same name for the ValidationGroup.  If I hit my Retrieve button I then get the Invalid Date Entered message.

How do I get the RegularExpressionValidator to display the message in the ValidationSummary like the RequiredFieldValidator?

Also, how do I get the * to show next to the date field rather than below it?

Any help is greatly appreciated!
Avatar of dyarosh
dyarosh

ASKER

I forgot to post my markup.  Here it is:

    <asp:ValidationSummary ID="ValidationSummary1" ValidationGroup="NewHireEmails" runat="server" BackColor="Red" BorderStyle="solid" Font-Bold="True" ForeColor="White" />
    <table>
        <tr>
            <td>Enter the Hire Date to Report:</td>
            <td>
                <asp:TextBox ID="txtHireDate" runat="server" MaxLength="10" Text="" ClientIDMode="Static"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                    ErrorMessage="Hire Date Required"  ValidationGroup="NewHireEmails"
                    ControlToValidate="txtHireDate" Display="Dynamic" 
                    ToolTip="Enter Hire Date" BackColor="Red" Font-Bold="True" ForeColor="White" SetFocusOnError="True" Text="*"></asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                    ErrorMessage="Invalid Date entered" ControlToValidate="txtHireDate" Display="Dynamic"  
                    ToolTip="Enter a date in the format MM/DD/YYYY or MM/DD/YY" Text="Invalid Date entered"
                    ValidationGroup="NewHireEmails"  BackColor="Red" Font-Bold="True" ForeColor="White"
                    ValidationExpression="^(((((((0?[13578])|(1[02]))[\.\-/]((0?[1-9])|([12]\d)|(3[01])))|(((0?[469])|(11))[\.\-/]((0?[1-9])|([12]\d)|(30)))|((0?2)[\.\-/]((0?[1-9])|(1\d)|(2[0-8]))))[\.\-/](((19)|(20))?([\d][\d]))))|((0?2)[\.\-/](29)[\.\-/](((19)|(20))?(([02468][048])|([13579][26])))))$"></asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td><asp:Button ID="btnRetrieveNewHires" runat="server" Text="Retrieve New Hires" validationgroup="NewHireEmails"
                    onclick="btnRetrieveNewHires_Click" /></td>
            <td><asp:Button ID="btnSendEmail" runat="server" Text="Send Emails" OnClick="btnSendEmail_Click" Enabled="false" /></td>
            <td><asp:Button ID="btnSaveFile" runat="server" Text="Export To Excel" OnClick="btnSaveFile_Click" Enabled="false" /></td>
            <td><asp:Button ID="btnReturn" runat="server" ClientIDMode="Static"
                    Text="Return to Employee Profile Menu" onclick="btnReturn_Click" /></td>
        </tr>
    </table>

Open in new window

Avatar of Obadiah Christopher
Well.. Try tabbing out of the textbox without entering any date.

ValidationSummary will be fired only on clicking of the submit button.
The Validation Summary is displayed when you try to submit the form (click the submit button), and not exactly after you fill in the form fields.

If you have Display="Dynamic" on your validator, like you have, the only thing you'll instantly get is the message in your validator's Text property. So, if you want to instantly get the error message,
you'll have to set Text="Invalid date Entered".

hope this helps.
Avatar of dyarosh

ASKER

Is there a way to get the * to show up to the right of the textbox rather than below it?
ASKER CERTIFIED SOLUTION
Avatar of jitendra patil
jitendra patil
Flag of India 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
Avatar of dyarosh

ASKER

What browser and version are you using?  Here is my markup and the error message still appears below the textbox.

                <asp:TextBox ID="txtHireDate" runat="server" MaxLength="10" Text="" ClientIDMode="Static"></asp:TextBox><asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                    ErrorMessage="Invalid Date entered" ControlToValidate="txtHireDate" Display="Dynamic"  
                    ToolTip="Enter a date in the format MM/DD/YYYY or MM/DD/YY" Text="Invalid Date entered"
                    BackColor="Red" Font-Bold="True" ForeColor="White"
                    ValidationExpression="^(((((((0?[13578])|(1[02]))[\.\-/]((0?[1-9])|([12]\d)|(3[01])))|(((0?[469])|(11))[\.\-/]((0?[1-9])|([12]\d)|(30)))|((0?2)[\.\-/]((0?[1-9])|(1\d)|(2[0-8]))))[\.\-/](((19)|(20))?([\d][\d]))))|((0?2)[\.\-/](29)[\.\-/](((19)|(20))?(([02468][048])|([13579][26])))))$"></asp:RegularExpressionValidator>

Open in new window

Avatar of dyarosh

ASKER

I ended up having to put a width on my textbox in order to get the error message to display to the right of the textbox.