验证者 [英] Validators
本文介绍了验证者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个文本框,在两个文本框中我都输入了日期.我想问问第二个文本框中输入的日期不应大于第一个文本框中的日期.我想使用比较验证器,请尽可能给我代码.
I have two textboxes.In both textboxes i entered dates. I want to chaeck that date entred in second textbox should not be greater than first text box. I want to use compare validator, Plz give me code if possible.
推荐答案
因为文本框是"Date
"字段,而不是"Numeric
"字段,您需要使用Custom validator
(要使用自定义javascript代码验证文本框的值).
您可以在这里 [
As the text boxes are "Date
" fields, and not "Numeric
" fields, you need to useCustom validator
(To validate the text box values using a custom javascript code).
You can have a look Here[^] to see how to implement a Custom Validator.
Inside the custom validator javascript function, you should get the date values from the two date fields, compare them and then setargs.IsValid
= true or false.
Good luck.
无需验证,您也可以执行此操作.
With out validation also you can do this.
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
DateTime a = DateTime.Parse(TextBox1.Text);
DateTime b = DateTime.Parse(TextBox2.Text);
if (a > b)
{
Response.Write(("<script>alert('Check date range')</script>");
TextBox2.Text="";
}
这篇关于验证者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文