Asp.net compare validator to validate date

后端 未结 4 658
南方客
南方客 2021-01-04 11:36

As you all know Compare validators can be used to validate dates and check based on operator type (<, <= , >= etc). I have set the cultureinvariantvalues=\"true\

4条回答
  •  温柔的废话
    2021-01-04 12:26

    Try custom Validator and at the code behind at onservervalidate event convert the text to DateTime and then do the comparision.

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

提交回复
热议问题