我更喜欢使用asp.net验证控件,因为我目前在同一视图中有其他验证控件。我需要错误的信息来显示一个验证摘要。
我有两个文本框,我需要确保textboxA是LessThan textboxB。
我使用了CompareValidator并将属性设置为:
以下是问题所在:
在“更新”按钮的Click事件中,我添加了以下代码,因为我只需要它来验证textboxA/textboxB != null。
if(String.IsNullOrEmpty(textboxB.Text))
{
Debug.Write("Valid");
timeCompareValidator.IsValid = true;
}提前感谢您的帮助。
克莱尔
发布于 2009-09-25 08:56:07
如果我没听错,你需要比较两个日期。
我在msdn上找到了这段代码
DateTime date1 = new DateTime(2009, 8, 1, 0, 0, 0);
DateTime date2 = new DateTime(2009, 8, 1, 12, 0, 0);
int result = DateTime.Compare(date1, date2);
string relationship;
if (result < 0)
relationship = "is earlier than";
else if (result == 0)
relationship = "is the same time as";
else
relationship = "is later than";
Console.WriteLine("{0} {1} {2}", date1, relationship, date2);
// The example displays the following output:
// 8/1/2009 12:00:00 AM is earlier than 8/1/2009 12:00:00 PM发布于 2009-09-25 09:02:42
是否尝试将if语句更改为:
if (!string.IsNullOrEmpty(textboxA.Text) && !string.IsNullOrEmpty(textboxB.text))发布于 2009-09-25 09:19:14
如果要比较服务器端的两个日期或时间,请使用此解决方案
DateTime dt1 = Convert.ToDateTime(TextBoxA.Text);
DateTime dt2 = Convert.ToDateTime(TextBoxB.Text);
int result = dt1.CompareTo(dt2)https://stackoverflow.com/questions/1476161
复制相似问题