asp.net中的日期和时间验证 [英] Date and time validation in asp.net

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

问题描述

大家好,我正在使用datetimepiker来选择日期和时间,我想检查开始日期不应该大于结束日期和日期时间在asp.net验证



我的日期时间格式是这样的 - 2014-01-08 11:26



i我也使用比较验证但不工作



hello everyone,i am using datetimepiker to pick date and time ,i want to check start date should not greater than end date and Date time Validation in asp.net

my datetime format is like this-2014-01-08 11:26

i am also using compare validation but not working

<asp:CompareValidator ValidationGroup="examvalidation" ID="cmpVal1" ControlToCompare="txtstarttime"

                                                   ControlToValidate="txtendttime" Type="Date" Operator="GreaterThanEqual" ForeColor="Red"

                                                   ErrorMessage="Start date should not greater than end date" runat="server"></asp:CompareValidator>

< br $> b $ b





请帮帮我





please help me

推荐答案

据我所知,您无法检查比较验证器中的日期时间格式,但您可以检查是否只有date.so,更好

使用自定义验证器



Upto my knowledge,you cant check the datetime format in compare validator,but you can check if only date.so,better
use custom validator

protected void DateTimeComparision_ServerValidate(object source, ServerValidateEventArgs args)
    {
        args.IsValid = Convert.ToDateTime(txtStartDate.Text) < Convert.ToDateTime(txtFinishDate.Text);
    }


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

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