Solved

How to compare from date and to date using validator.

Posted on 2012-04-02
7
302 Views
Last Modified: 2012-04-03
<td  class="td_style  report_color" style="width:auto">
            <div align="left">
                <asp:TextBox ID="txtfdate" runat="server" CssClass="report_color" Width="200px"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                    ControlToValidate="txtfdate" ErrorMessage="*"></asp:RequiredFieldValidator>
            </div>
               
           </td>
           </tr>
           <tr>
            <td  class="td_style  report_color" style="width:auto">
            <div align="right">
                <asp:Label ID="Label2" runat="server" Text="Select To Date"></asp:Label>
                </div>
           </td>
           
            <td  class="td_style  report_color" style="width:auto">
            <div align="left">
                <asp:TextBox ID="txttdate" runat="server" CssClass="report_color" Width="200px"></asp:TextBox>
                <asp:CompareValidator ID="CompareValidator2" runat="server"
                    ControlToCompare="txtfdate" ControlToValidate="txttdate"
                    ErrorMessage="Should be more than From Date"></asp:CompareValidator>
            </div>
               
           </td>
0
Comment
Question by:searchsanjaysharma
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:Codecaesar
ID: 37795771
0
 

Author Comment

by:searchsanjaysharma
ID: 37795823
<td  class="td_style  report_color" style="width:auto">
            <div align="left">
                <asp:TextBox ID="txtfdate" runat="server" CssClass="report_color" Width="200px"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                    ControlToValidate="txtfdate" ErrorMessage="*"></asp:RequiredFieldValidator>
            </div>
               
           </td>
           </tr>
           <tr>
            <td  class="td_style  report_color" style="width:auto">
            <div align="right">
                <asp:Label ID="Label2" runat="server" Text="Select To Date"></asp:Label>
                </div>
           </td>
           
            <td  class="td_style  report_color" style="width:auto">
            <div align="left">
                <asp:TextBox ID="txttdate" runat="server" CssClass="report_color" Width="200px"></asp:TextBox>
               <asp:CustomValidator ID="CustomValidator1"
 OnServerValidate="ValidateDuration" ControlToValidate="txttdate"
 
    ErrorMessage="Dates are too far apart" runat="server" />
   

Not working
0
 
LVL 15

Accepted Solution

by:
navneethegde earned 500 total points
ID: 37795996
Hi!
                <td class="td_style  report_color" style="width: auto">
                    <div align="left">
                        <asp:TextBox ID="txttdate" runat="server" CssClass="report_color" Width="200px"></asp:TextBox>
                        <asp:CompareValidator ID="CompareValidator2" runat="server" ControlToCompare="txtfdate"
                            ControlToValidate="txttdate" Operator="GreaterThan" Type="Date" ErrorMessage="Should be more than From Date"></asp:CompareValidator>
                    </div>
                </td>

Open in new window


Update this and try

Thanks!
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 15

Expert Comment

by:navneethegde
ID: 37796003
only added
Operator="GreaterThan" Type="Date" 

Open in new window

check if this helps


Thanks!
0
 

Author Comment

by:searchsanjaysharma
ID: 37796019
How to empty the txttdate when validation occurs
0
 
LVL 2

Expert Comment

by:Codecaesar
ID: 37796186
<tr>
    <td  class="td_style  report_color" style="width:auto">
            <div align="left">
                <asp:TextBox ID="txtfdate" runat="server" CssClass="report_color" Width="200px"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                    ControlToValidate="txtfdate" ErrorMessage="*"></asp:RequiredFieldValidator>
            </div>
               
     </td>
    </tr>
           <tr>
            <td  class="td_style  report_color" style="width:auto">
            <div align="right">
                <asp:Label ID="Label2" runat="server" Text="Select To Date"></asp:Label>
                </div>
           </td>
           </tr>
    <tr>
            <td  class="td_style  report_color" style="width:auto">
            <div align="left">
                <asp:TextBox ID="txttdate" runat="server" CssClass="report_color" Width="200px"></asp:TextBox>
                <asp:CompareValidator ID="CompareValidator2" runat="server"
                    ControlToCompare="txtfdate" ControlToValidate="txttdate"
                    ErrorMessage="Should be more than From Date"></asp:CompareValidator>
            </div>      
           </td>
        </tr>
Screen-1.jpg
screen-2.jpg
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37800441
ok
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

815 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

8 Experts available now in Live!

Get 1:1 Help Now