[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

compare validator asp.net, c#

Posted on 2009-05-08
7
Medium Priority
?
694 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 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