本文介绍了我需要结束时间必须大于开始时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个开始时间,结束时间在我的网页上。
我需要结束时间必须大于开始时间,开始时间是当前时间和结束时间是用户输入使用Masked Extender
。如何实现此验证?
I am having a start time,end time on my web page.
I need to end time must be greater than start time and start time is current time& end time is user entry using Masked Extender
.How can I achieve this validation?
推荐答案
<asp:Textbox runat="server" ID="TextBox1" />
<asp:CustomValidator runat="server" ControlToValidate="TextBox1" ErrorMessage="Date was in incorrect format" OnServerValidate="CustomValidator1_ServerValidate" />
代码落后:
Code behind:
protected void CustomValidator1_ServerValidate(object sender, ServerValidateEventArgs e)
{
DateTime d;
e.IsValid = DateTime.TryParseExact(e.Value, new[] { "dd/MM/yyyy", "yyyy-MM-dd" }, CultureInfo.InvariantCulture, DateTimeStyles.None, out d);
}
== OR ==
==OR==
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CompareValidator ID="DateValidator" runat="server" Operator="DataTypeCheck"
Type="Date" ControlToValidate="TextBox1" ErrorMessage="Bad format" />
祝你好运,
OI
Good luck,
OI
<asp:comparevalidator></asp:comparevalidator>
验证日期
<asp:CustomValidator ID="cstmvEndDate" ControlToValidate="txtEndTime" ClientValidationFunction="compareTime" Display="Dynamic" ErrorMessage="End time should be greater than Start time!" ValidationGroup="Validation"runat="server" />
这篇关于我需要结束时间必须大于开始时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!