asp.net中的日历扩展程序 [英] calendar extender in asp.net
本文介绍了asp.net中的日历扩展程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的比较验证器验证出生日期应小于当前日期如下
My compare validator to validate date of birth should be less than current date is as follows
<asp:CompareValidator ID="DateOfBirthValidator" runat="server" ValidationGroup="AddRecord"
ForeColor="Red" ControlToValidate="txtBirth" ControlToCompare="txtDate" Operator="LessThan"
Type="Date" ErrorMessage="Date of birth should be less than current date." CultureInvariantValues="true" SetFocusOnError="true"></asp:CompareValidator>
但它只验证日期和月份不是一年。如何解决该问题
But it only validate day and month not the year. How can I solve that problem
推荐答案
将CustomValidator与服务器端验证一起使用如下
use CustomValidator with server side validation as below
<asp:Calendar ID="calendarBirthDay" OnSelectionChanged="Selection_Changed" runat="server"></asp:Calendar>
<asp:CustomValidator ID="DateOfBirthValidator" OnServerValidate="DateCustVal_Validate" runat="server"></asp:CustomValidator>
服务器端代码示例:
server side code sample :
protected void DateCustVal_Validate(object source, ServerValidateEventArgs args)
{
args.IsValid = calendarBirthDay < DateTime.Today;
}
1。CompareValidator
与LessThan
运算符一起使用验证值格式ControlToValidate
的值小于ControlToCompare
的值。
2.在你的情况下,2DateTime
比较对象,可能是同一年甚至同一只蛾只有一天不同的情况,所以没有问题,只是<$的正常行为c $ c> CompareValidator 。
3.如果要更改正常行为,则应实现自定义比较验证器。请参阅下一个链接: http://msdn.microsoft.com/en- us / library / 9eee01cx(v = vs.71).aspx [ ^ ]
http://forums.asp.net/t/1238727.aspx?custom+compare+validator [ ^ ]
1.CompareValidator
used withLessThan
operator validate that the value formControlToValidate
has a value less then the value fromControlToCompare
.
2.In your case, 2DateTime
objects are compared, and could be the situation that for the same year and even the same moth only the day is different, so there is no problem, is just the normal behavior of theCompareValidator
.
3. If you want to change the normal behavior you should implement a custom compare validator. See the next links: http://msdn.microsoft.com/en-us/library/9eee01cx(v=vs.71).aspx[^]
http://forums.asp.net/t/1238727.aspx?custom+compare+validator[^]
这篇关于asp.net中的日历扩展程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文