显示错误时,asp.net中的比较验证器和文本框将清除 [英] Compare validator in asp.net and Textbox is clear when error display

查看:56
本文介绍了显示错误时,asp.net中的比较验证器和文本框将清除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hii ,,

我在C#中使用比较验证器.有两个文本框"Todate"和"from date".至今不少于fromdate.所以我像这样使用:

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: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">


它提供了完美的结果,但是当比较验证器给出错误时,我想清除文本框,因为当我单击提交"按钮时,它会接受所有我不想要的值.
todate小于From_date时,to_date文本框为空

救救我..

Mitesh


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

推荐答案

使用Coustom验证器.
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;
   }
  }


这篇关于显示错误时,asp.net中的比较验证器和文本框将清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆