Solved

compare validator asp.net, c#

Posted on 2009-05-08
7
684 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
  • 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now