在asp.net中验证Calendar控件 [英] Validation for Calendar Control in asp.net
问题描述
嗨frnds,
正在使用asp.net C#。
我正在预约使用asp.net c#编程。这是Intranet项目。
在我的网页上,我有日历cotrol和一个按钮。
在这里,从日历控件中选择日期后,用户点击按钮重定向下一页......直到这里工作正常。
但我的要求是,我要验证日历控件如果用户没有选择日期并点击按钮....
我需要留言(请选择日期)
这可以为日历控制提供验证。
请帮忙。
谢谢。
检查以下代码
< asp: calendar id = startCalendar cssclass = startDate onselectionchanged = Selection_Changed RUNAT = <跨度class =code-string> server >
< ; asp:customvalidator id = dateCustVal onservervalidate = DateCustVal_Validate >
runat = server >
protected void DateCustVal_Validate( object source,ServerValidateEventArgs args)
{
if (startCalendar.SelectedDate == null
|| startCalendar.SelectedDate == new DateTime( 0001 , 1 , 1 , 0 , 0 , 0 ))
{
args.IsValid = false ;
}
else
{
args.IsValid = true 跨度>;
}
}
查看这些链接。
http://support2.microsoft.com/default.aspx?scid=kb;en-us; 310145 [ ^ ]
http://geekswithblogs.net/Bunch/archive/2009/02/17/quick-and-dirty-calendar-validation-date-required.aspx [ ^
Hi frnds,
am working on asp.net C#.
am creating an appointment progam using asp.net c#. It is Intranet Project.
On my webpage I have Calendar cotrol and a button.
Here, after selecting date from calendar control user clicks on button to redirect next page...till here its works fine.
But My requirement is, I want to Validate Calendar Control if user didnt select date and click on button....
I need message (Please Select Date)
Can this be possible to give validation for calendar control.
Please help.
Thanks.
Check the below code
<asp:calendar id="startCalendar" cssclass="startDate" onselectionchanged="Selection_Changed" runat="server" > <asp:customvalidator id="dateCustVal" onservervalidate="DateCustVal_Validate" > runat="server"> protected void DateCustVal_Validate(object source, ServerValidateEventArgs args) { if (startCalendar.SelectedDate == null || startCalendar.SelectedDate == new DateTime(0001, 1, 1, 0, 0, 0)) { args.IsValid = false; } else { args.IsValid = true; } }
Check these links .
http://support2.microsoft.com/default.aspx?scid=kb;en-us;310145[^]
http://geekswithblogs.net/Bunch/archive/2009/02/17/quick-and-dirty-calendar-validation-date-required.aspx[^]
这篇关于在asp.net中验证Calendar控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!