ValidationSummary Control With Date Range, Requiredfield, and Compare Validators.

I would like to get all of these controls to function together (and separately, where the case may be.....)
Attached is my code for the main table of start and end date but I am having trouble with the compare validation and the regularexpressionvalidator-
I have also attached a screenshot of my form.
I would like to get any/all of my validation checks to show up in the validation summary, or on the screen near the control.
Is this possible?
When I enter an invalid date the compare validator picks this up but the message flashes briefly across the form;  It is hidden inside the html tag.  Its like there is a lag when I click the View Report button.
When I click on View Source, I can see the message is written in the html - as "Bad Start Date"

Is there any way I can enable these date validation tags to show up all the time whenever the onblur event occurs, or to get this validation check to show up in the validationsummary?
Does the check have to happen on the onClick() event for the button?
Or, could I hook it to onblur for date validation?

Plus, I need the compare validator to make sure that the end date is greater than the start date.

Unless, someone knows of some javascript I could use to accomplish this???

Thanks

John

<table id="Table9" background="images/cell2_bkgrd.gif" runat="server" border="1"
                cellpadding="3" cellspacing="3" width="100%">
                <tr>
                  <td>
                  
                  <asp:ValidationSummary 
                  id="ValidationSummary1" 
                  DisplayMode="BulletList" 
                  runat="server"
                  HeaderText="Summary of Validation Errors:"
                  Font-Name="verdana"                 
                  Font-Size="9"/>
                  </td> 
                </tr>            
            </table> 
            
            <table id="tblContent" background="images/cell2_bkgrd.gif" runat="server" border="3"
                cellpadding="3" cellspacing="3" width="100%">
                <tr>
                    <td style="width: 340px; height: 30px;">
                        <b><font face="arial" size="2">Start Date:</font></b>
                        <asp:TextBox ID="startdate" runat="server" Width="120px" Text="" TabIndex="1" AutoPostBack="true"
                            MaxLength="10" >
                        </asp:TextBox>
                        <b><font face="arial" size="2">(MM/DD/YYYY) </font></b>
                    </td>
                    <td style="width: 340px; height: 30px;">
                        <b><font face="arial" size="2">End Date:</font></b>
                        <asp:TextBox ID="enddate" runat="server" Width="120px" Text="" TabIndex="2" AutoPostBack="true"
                            MaxLength="10" >
                        </asp:TextBox>
                        <b><font face="arial" size="2">(MM/DD/YYYY) </font></b>
                    </td>
                </tr>
            </table>
        
        <table id="Table8" background="images/cell2_bkgrd.gif" runat="server" border="0"
                cellpadding="3" cellspacing="3" width="100%">
                <tr>
                
                <td width="15%">
                <asp:RequiredFieldValidator 
                        ID="RequiredFieldValidator4" 
                        ControlToValidate="startdate"
                        Enabled="True"
                        Display="static" 
                        ErrorMessage="Start Date Required." 
                        runat="server"
                        SetFocusOnError="True" 
                        Font-Size="Small" />
                        <br /> 
              </td>
                                
                <td width="15%">
             <asp:CompareValidator 
                ID="DateValidator" 
                runat="server" 
                Operator="DataTypeCheck"
                Type="Date" 
                ControlToValidate="startdate" 
                Enabled="True"
                ErrorMessage="Bad Start Date Format" 
                Display="static" />
               <br /> 
                
               </td>
                                
                <td width="15%">
                  <asp:CompareValidator ID="CompareValidator4"
                        ControlToValidate="enddate"
                         ControlToCompare="startdate"
                         Display="static"
                         Text="End Date Must Be Greater Than Start Date!"
                         Operator="GreaterThan"
                         Type="Date"
                         Runat="Server" SetFocusOnError="true" Font-Size="Small" />
                </td>
                
                <td width="15%">
                <asp:RequiredFieldValidator 
                        ID="RequiredFieldValidator5" 
                        ControlToValidate="enddate"
                        Enabled="True"
                        Display="static" 
                        ErrorMessage="End Date Required." 
                        runat="server"
                        SetFocusOnError="True" 
                        Font-Size="Small" />
               
                <asp:CompareValidator 
                ID="CompareValidator1" 
                runat="server" 
                Operator="DataTypeCheck"
                Type="Date" 
                Enabled="True"
                ControlToValidate="enddate" 
                ErrorMessage="Bad End Date Format" />
                </td>
                </tr>
               
           
            </table>

Open in new window

screen.png
jtrapat1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David RobitailleAnalyst ProgrammerCommented:
ErrorMessage is the text in the ValidationSummary
Test is the "text" when the validation fail and is displayed at the validator is position. should work on "onblur"
Controls have a CausesValidation property. when set ot true, the validation is trigerred whan you use that control.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jtrapat1Author Commented:
davrob60-
thanks for the quick response-

I should have explained a little more about this form-
Its a little complicated because its sort of two parts-
The start date and end date at the top populate the client drop downlist before the bottom fields are filled.

So, if I could do this in an onblur event (validate the date and check if end date is greater than start date) before I click the View Report button, that would be great.
If not, Ill try to do it another way.

But, what bugs me is there is still a lag when the page submits.


Thanks.
John
0
David RobitailleAnalyst ProgrammerCommented:
Did you cnow you could use "ValidationGroup"?
if you put a the same validation group on validators and Control, thay will be linked on validation. use that in addition fo the CausesValidation (on the end date and start date) and give some new...
 
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

prairiedogCommented:
You should NOT set TextBox's AutoPostBack = True if you need to use validators.
0
jtrapat1Author Commented:
davrob60-
Thanks for all your help-
The page is almost there-
that CausesValidation property was the key -
all of the pages that I looked at for documentation never discussed this method.

One more question-
If I use the compare validator to test if enddate is greater than startdate, could it be attached to both start and end date?
Or do most people just include the test at end date?
For example, I have the attached test at the end date text box:

And I will look into the group validation-
it would be great to combine all of my tests into one.

Thanks again.

<td width="20%">
                  <asp:CompareValidator 
                  ID="CompareValidator4"
                  ControlToValidate="enddate"
                  ControlToCompare="startdate"
                  Display="static"
                  ErrorMessage="End Date Must Be Greater Than Start Date!"
                  Operator="GreaterThan"
                  Type="Date"
                  runat="Server" 
                  SetFocusOnError="true" 
                  Font-Size="X-Small" />
                </td>

Open in new window

0
David RobitailleAnalyst ProgrammerCommented:
i diden`t noticed that, goot shot, prairiedog!
0
prairiedogCommented:
Your code is fine if you set TextBox's AutoPostBack = False!!!
0
David RobitailleAnalyst ProgrammerCommented:
I just include the test at the end date, but i can`t speek for others...
0
David RobitailleAnalyst ProgrammerCommented:
But, wait a minute, i think he use AutoPostBack to populate it s  dropdownlist...
0
prairiedogCommented:
AutoPostBack and validators do not go together, they contradict each other.
The main reason of using validator is to validate data without having PostBacks. AutoPostBack defeats the purpose.
0
David RobitailleAnalyst ProgrammerCommented:
ok, but it<s point is th have the data post back if it<s correctly completed. that why the use of a ValidationGroup help.
if all fileds are valid, then the postback appen and the dropdown are populated. if not, then the validation process "block" the postback and the error massage is displayed...
When well used, they dont contradict each other...
0
prairiedogCommented:
You misunderstood my point. I said AutoPostBack contradict validator, not PostBack.
Here is what is happening in the author's question:
When user enter a value in one of the TextBox, and click the button. Now, the validator should check all input. But since the TextBox's AutoPostBack is True, so when the user clicks the button, TextBox's TextChanged event fired  and caused a postback, that is why the error message flashes and disappears. Then if you click the button again, everything is fine, it is because no value changes in TextBox so no event fires, and validator works fine.
0
David RobitailleAnalyst ProgrammerCommented:
And that why a text box with AutoPostBack=true should have CausesValidation=true.
That way, the TextChanged event is not fired when a validator is "in error"
So, jtrapat1, that discution should be instructive to you, but how your things are going???
0
prairiedogCommented:
>>>And that why a text box with AutoPostBack=true should have CausesValidation=true.
Sounds right, but please try it to see the result.
0
jtrapat1Author Commented:
Thanks to you both for the discussion-
Since Im paranoid- and since more is more, I set the AutoPostBack=true and CausesValidation=true. and it seems to be working.

Ive had a lot of trouble with this page -since it spun off from a SSRS that we wanted to customize.

Itried it without and it did work prairiedog so you were both correct -

Points rewarded and well worth it!

Thanks
0
prairiedogCommented:
>>>I set the AutoPostBack=true and CausesValidation=true. and it seems to be working.
Really? Hmmm, it does not work for me. It always generates a postback and screnn flashes.
Here is what I tested: I enter "qw" in the startdate, then use the tab key to move to the next field, then the error message dispalys and screen flashes and error message goes away.
0
jtrapat1Author Commented:
prairiedog-
You are right- my mistake!
I need the postback to populate the dropdown so I call loadclient() in each _textchanged event of startdate and enddate.
As long as the validation controls confirm before the button is clicked, my page is working.

Thanks again.

John
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.