Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii,,

i use compare validator in c#. there are two textboxes Todate and from date. todate is not less than fromdate. so i use like :
ASP.NET
<asp:CompareValidator ID="cm1" runat="server" Operator="LessThanEqual" Type="Date" ControlToValidate="txt_from_date" ControlToCompare="txt_to_date" ErrorMessage="To date not less than From date" Display="Dynamic" SetFocusOnError="True">

it gives perfact result but i want to clear the textbox when compare validator gives an error because when i click on submit button it takes all values that i not want.
when todate becomes less than from From_date the to_date textbox Become null

Help Me..

Mitesh
Posted
Updated 26-Jun-12 1:13am
v2
Comments
sandeep nagabhairava 26-Jun-12 7:31am    
have you any button click event?
when the error message displayed? i mean in which event?
[no name] 26-Jun-12 7:41am    
2 ajax calendar and when to date is less than from date compare validator gives message.

1 solution

Use Coustom validator.
function ClientValidate(source, arguments)
  {
var objFrom= document.getElementById('<%# txt_from_date.ClientID %>');
var objTo= document.getElementById('<%# txt_to_date.ClientID %>');

if (Date.parse(objFrom.value) > Date.parse(objTo.value))
   {
   objFrom.value='';
   objTo.value='';
   arguments.IsValid=false;
   }

else
   {
    arguments.IsValid=true;
   }
  }
 
Share this answer
 
Comments
[no name] 26-Jun-12 8:26am    
not working...........

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900