Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2008-10-31
17
770 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:jtrapat1
  • 7
  • 6
  • 4
17 Comments
 
LVL 18

Accepted Solution

by:
David Robitaille earned 450 total points
ID: 22850400
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
 

Author Comment

by:jtrapat1
ID: 22850552
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
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22850677
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 22

Expert Comment

by:prairiedog
ID: 22850827
You should NOT set TextBox's AutoPostBack = True if you need to use validators.
0
 

Author Comment

by:jtrapat1
ID: 22850865
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
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22850876
i diden`t noticed that, goot shot, prairiedog!
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22850894
Your code is fine if you set TextBox's AutoPostBack = False!!!
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22850907
I just include the test at the end date, but i can`t speek for others...
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22850930
But, wait a minute, i think he use AutoPostBack to populate it s  dropdownlist...
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22851026
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
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22851073
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
 
LVL 22

Expert Comment

by:prairiedog
ID: 22851211
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
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22851310
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
 
LVL 22

Assisted Solution

by:prairiedog
prairiedog earned 50 total points
ID: 22851403
>>>And that why a text box with AutoPostBack=true should have CausesValidation=true.
Sounds right, but please try it to see the result.
0
 

Author Comment

by:jtrapat1
ID: 22851450
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
 
LVL 22

Expert Comment

by:prairiedog
ID: 22851524
>>>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
 

Author Comment

by:jtrapat1
ID: 22851557
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb.net class 3 21
Add or delete table rows 10 53
How to filter by key press ? 6 20
Validating textboxes in red square borders. 2 10
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question