Solved

compare validator asp.net, c#

Posted on 2009-05-08
7
691 Views
Last Modified: 2013-12-17
Hi i have the following code

 <asp:RegularExpressionValidator ID="Year" runat="server" ControlToValidate="txtdate"
            ErrorMessage="Please Enter yyyy-mm" ValidationExpression="(19|20)\d\d-(0[1-9]|1[012])"></asp:RegularExpressionValidator>

which makes sure that the date entered is on yyyy-mm format

i also have two text bos one is txtDate which is start date and the other is txtEnddate,

What i want to do is compare it so that the end date is never less than start bearing in mind the format i have given.

Please help


Thanks,

R8VI
0
Comment
Question by:R8VI
[X]
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
  • 3
  • 2
  • 2
7 Comments
 
LVL 15

Expert Comment

by:NazoUK
ID: 24334708
<asp:CompareValidator runat="server" ControlToValidate="txtEndDate" ControlToCompare="txtDate" Operator="GreaterThanEqual" Type="Date" ErrorMessage="End Date must not be before Start Start" />
0
 

Author Comment

by:R8VI
ID: 24334770
Hi,

thanks for thsi but this doens twork in the sense for example if i put 1999-04 as start date and then put 1999-01 as end date the validation works no problem but then if i put in correct information for example as 1999-06 as end date validation will still appear.

Please help

Thanks,

R8VI
0
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 24334817
hi R8VI,

               you have add a CompareValidator control in your page, which helps u to compare between your txtDate textBox and textEnddate textBox.
<asp:CompareValidator ID="CompareValidator1" runat="server" 
            ControlToCompare="txtDate" ControlToValidate="textEnddate" ErrorMessage="end date is never less than start" 
            Operator="GreaterThanEqual" Type="Date"></asp:CompareValidator>

Open in new window

0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 24334858
hi R8VI,
              check the link for regular expression.

http://www.regular-expressions.info/regexbuddy/dateyyyymmdd.html
0
 

Author Comment

by:R8VI
ID: 24334931
Hi, thanks for this here is the code but doesnt work i have the regular expression validator thats works so no problem just trying to get the compare validator to work first

<asp:TextBox ID="txtdate" runat="server"></asp:TextBox>
     
        <asp:CompareValidator ID="CompareValidator5" runat="server"
            ControlToCompare="txtdate" ControlToValidate="txtenddate" ErrorMessage="end date is never less than start"
            Operator="GreaterThanEqual" Type="Date"></asp:CompareValidator>
              <asp:TextBox ID="txtenddate" runat="server"></asp:TextBox>
        <asp:Label ID="lblLabeltest" runat="server" Text="End Date must not be before Start Start" Visible="false"></asp:Label>

please help,

Thanks,

R8VI
0
 
LVL 15

Accepted Solution

by:
NazoUK earned 500 total points
ID: 24335145
In this case you'd have to use a custom validator that inspects the values in the two textboxes, breaks up the numbers and works out if they are valid. You can't use a standard compare operator as you aren't actually using valid dates.
0
 

Author Comment

by:R8VI
ID: 24335248
ahhh ok kul thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Selenium: Transitioning from unit testing to automated testing 4 62
Build a string of emails from a gridview 2 20
C# LINQ 5 27
c# ftp code 3 35
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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