验证日期 [英] Validating Dates

查看:101
本文介绍了验证日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个下拉框(fromDay,fromMonth,ToDay和ToMonth)


我希望能够测试以确保日期有效并且

从日期开始< To to dates。


当我将记录添加到数据库时,我通常使用类似的东西:

FromMonth.SelectedValue& " / 01 /" &安培; FromYear.SelectedValue


我还在屏幕上显示其他验证器,用于发送电子邮件和必填字段。


如何设置验证器来处理这种情况?


我正在设置一个自定义验证器或一个CompareValidator来处理

字段。我需要将变量移动到一个临时变量

进行测试(sting或label)。


问题是它需要在我之后开火设置临时的

变量。所有其他的验证器都会在提交时触发。


如何设置此验证器以便在其他验证器之后启动并在我完成之后

设置变量为它要验证吗?


谢谢,


Tom

解决方案

< blockquote> tshad写道:

我有4个下拉框(fromDay,fromMonth,ToDay和ToMonth)

我希望能够测试以确保日期有效
起始日期是< To to dates。

当我将记录添加到数据库时,我通常会使用以下内容:

FromMonth.SelectedValue& " / 01 /" &安培; FromYear.SelectedValue

我还在屏幕上有其他验证器用于发送电子邮件和必填字段。

如何设置验证器来处理这种情况?
<我正在设置一个自定义验证器或一个CompareValidator来处理这些字段。我需要将变量移动到临时变量中进行测试(sting或标签)。

问题是我需要在设置临时变量后触发
变量。所有其他的验证器都会在提交时触发。

我如何设置这个验证器以便在其他人之后启动并在我设置变量以进行验证之后?

谢谢,

Tom



混合验证器可能真的很痛苦。这就是我最终将
转移到100%CustomValidators的原因。你仍然无法控制他们验证的

订单,但至少他们都会在相同的时间内验证。如果您需要控制订单,您可能需要创建自己的

标签/等,并将其全部转换为一个在IsPostBack上激活的函数()


-

Curt Christianson

网站: http: //www.darkfalz.com

博客: http:/ /blog.darkfalz.com


" Curt_C [MVP]" < software_at_darkfalz.com>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP14.phx.gbl ...

tshad写道:

我有4个下拉框(fromDay,fromMonth,ToDay和ToMonth)

我希望能够测试以确保日期有效并且
From日期< To to dates。

当我将记录添加到数据库时,我通常会使用以下内容:

FromMonth.SelectedValue& " / 01 /" &安培; FromYear.SelectedValue

我还在屏幕上显示其他验证器,用于发送电子邮件和所需的
字段。

如何设置验证器来处理这种情况?

我正在设置自定义验证器或CompareValidator来处理字段。我需要将变量移动到一个临时的变量中进行测试(sting或label)。

问题是它需要在我设置临时后触发
变量。所有其他的验证器都会在提交时触发。

如何设置此验证器以便在其他人之后以及在我设置变量以进行验证后启动它?

谢谢,

Tom Mixing验证器可能是一个真正的痛苦。这就是我最终移动到100%CustomValidators的原因。您仍然无法控制他们验证的订单,但至少他们都会同时验证。如果您需要控制订单,您可能需要创建自己的标签/ etc
并将其全部滚动到一个在IsPostBack()上触发的函数




但是我设置了

asp后如何才能触发CustomValidator:标签:


FromDate.Text = FromMonth.SelectedValue &安培; " / 01 /" &安培; FromYear.SelectedValue

ToDate.Text = ToMonth.SelectedValue& " / 01 /" &安培; ToYear.SelectedValue


现在验证


此外,验证它的最佳方法是什么?我正在努力确保

FromDate等于或等于ToDate


谢谢,


Tom

-
Curt Christianson
网站: http: //www.darkfalz.com
博客: http://blog.darkfalz .com




但是如何在设置后触发CustomValidator
asp:标签:



自定义验证器应该自动触发回发,如果没有

做一个page.Validate()调用和一个page.IsValid()检查它是否通过。

-

Curt Christianson

网站: http://www.darkfalz.com

博客: http://blog.darkfalz.com


I have 4 dropdown boxes (fromDay, fromMonth, ToDay and ToMonth)

I want to be able to test to make sure that the dates are valid and the the
From dates are < the To dates.

When I add the records to the database, I typically use something like:

FromMonth.SelectedValue & "/01/" & FromYear.SelectedValue

I also have other validators on the screen for emails and required fields.

How would I set up a validator to handle this situation?

I was looking at setting a Custom validator or a CompareValidator to handle
the fields. I would need to move the variables into a temporary variable
for testing (sting or label).

The problem is that it would need to fire after I set up the temporary
variables. All the other validators would fire on submit.

How would I set up this validator to fire after the others and after I have
set up the variables for it to Validate?

Thanks,

Tom

解决方案

tshad wrote:

I have 4 dropdown boxes (fromDay, fromMonth, ToDay and ToMonth)

I want to be able to test to make sure that the dates are valid and the the
From dates are < the To dates.

When I add the records to the database, I typically use something like:

FromMonth.SelectedValue & "/01/" & FromYear.SelectedValue

I also have other validators on the screen for emails and required fields.

How would I set up a validator to handle this situation?

I was looking at setting a Custom validator or a CompareValidator to handle
the fields. I would need to move the variables into a temporary variable
for testing (sting or label).

The problem is that it would need to fire after I set up the temporary
variables. All the other validators would fire on submit.

How would I set up this validator to fire after the others and after I have
set up the variables for it to Validate?

Thanks,

Tom


Mixing validators can be a real pain. This is the reason I ended up
moving to 100% CustomValidators. You still dont get much control on the
order they validate, but at least they will all validate at the same
time. If you need to control the order you may want to create your own
labels/etc and roll it all into one function that fires on IsPostBack()

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com


"Curt_C [MVP]" <software_at_darkfalz.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...

tshad wrote:

I have 4 dropdown boxes (fromDay, fromMonth, ToDay and ToMonth)

I want to be able to test to make sure that the dates are valid and the
the From dates are < the To dates.

When I add the records to the database, I typically use something like:

FromMonth.SelectedValue & "/01/" & FromYear.SelectedValue

I also have other validators on the screen for emails and required
fields.

How would I set up a validator to handle this situation?

I was looking at setting a Custom validator or a CompareValidator to
handle the fields. I would need to move the variables into a temporary
variable for testing (sting or label).

The problem is that it would need to fire after I set up the temporary
variables. All the other validators would fire on submit.

How would I set up this validator to fire after the others and after I
have set up the variables for it to Validate?

Thanks,

Tom Mixing validators can be a real pain. This is the reason I ended up moving
to 100% CustomValidators. You still dont get much control on the order
they validate, but at least they will all validate at the same time. If
you need to control the order you may want to create your own labels/etc
and roll it all into one function that fires on IsPostBack()



But how do I get the CustomValidator to fire after I have set up the
asp:Labels:

FromDate.Text = FromMonth.SelectedValue & "/01/" & FromYear.SelectedValue
ToDate.Text = ToMonth.SelectedValue & "/01/" & ToYear.SelectedValue

Validate it now

Also, what would be the best way to validate it? I am trying to make sure
the FromDate is before or equal to the ToDate

Thanks,

Tom

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com




But how do I get the CustomValidator to fire after I have set up the
asp:Labels:


The custom validator should fire on the postback automatically, if not
do a page.Validate() call and a page.IsValid() check to see if it passed.
--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com


这篇关于验证日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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