ASP.NET: What is the best way to check the three drop-down windows that are used to select a date (month, day, year)?

I have two sets of crashes for the start and end dates. Each date is created by selecting the month, day, and year from three separate drop-down lists. I currently have RequiredFieldValidators in all of the dropdowns (which only show * if nothing else has been selected), but I need to check that the end date is greater than the start date. I can take care of the logic of comparing dates, but from the point of view of the validation method used can someone help me (I, in fact, need to check six drop-down lists at the same time)? I tried custom validation using client-side javascript, but couldn't get it to work. Can you even check multiple dropdowns using ASP.NET validation elements? (this is what I would like to do - I can always write javascript,but tried to stay away from this).

Thank.

+3
source share
2 answers

Use a special validator without a control to validate the populated field, then use it on the aspx page:

<script type="text/javascript">
<!--
    ValidatorHookupControlID("<%= ctrl1.ClientID %>",
     $get("<%= customValidator.ClientID %>"));
    ValidatorHookupControlID("<%= ctrl2.ClientID %>",
     $get("<%= customValidator.ClientID %>"));
    ValidatorHookupControlID("<%= ctrl3.ClientID %>",
     $get("<%= customValidator.ClientID %>"));
//-->
</script>

Edit: I found a tutorial that better explains what I mean here

+4
source

Source: https://habr.com/ru/post/1747715/


All Articles