How can I use CompareValidator for times without dates?

后端 未结 3 1642
广开言路
广开言路 2020-12-11 20:37

When I enter 9:00 into the Start control, and 16:00 into Finish; the code below fails validation.

Does anybody know a way I can use the ASP.NET val

相关标签:
3条回答
  • 2020-12-11 20:49

    This appearently cannot be done.

    For the record; I used a custom validator.

    EDIT: Here's my custom validator code in case anyone (i.e. alhambraeidos) needs it. Please note, this code replaces my sample control names (txtStart & txtFinish) with actual names from my app (txtReady & txtClose).

    try
    {
        // parse & compare dates
        string randomDt = "01/01/2000 ";
        args.IsValid = DateTime.Parse(randomDt + txtClose.Text) > DateTime.Parse(randomDt + txtReady.Text);
    }
    catch(Exception /*ex*/)
    {
        // exception is assumed to be invalid times entered
        args.IsValid = false;
    }
    
    0 讨论(0)
  • 2020-12-11 20:49

    try to change the Type property to String, it should work.

    0 讨论(0)
  • 2020-12-11 21:11

    Compare validator allowable types are: Stinrg, Integer, Double, Date (no time) Currency

    0 讨论(0)
提交回复
热议问题