Validate month

4 posts, 2 answers
  1. Ivy
    Ivy avatar
    30 posts
    Member since:
    Feb 2013

    Posted 22 Apr 2013 Link to this post

    Hi,

    How to check and validate that the month selected from the second radmonthyear picker comes after the month selected from first radmonthyearpicker?

    Thanks
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 Apr 2013 Link to this post

    Hi,

    You can use ASP RequiredFieldValidator to ensure that both the fields are not left blank and an ASP CompareValidator to make sure that the second date selection comes after the first. Please have a look at the below mark up.

    ASPX:
    <asp:CompareValidator ID="dateCompareValidator" runat="server" ControlToValidate="RadMonthYearPicker2"
        ControlToCompare="RadMonthYearPicker1" Operator="GreaterThan" Type="Date" ErrorMessage="The second date must be after the first one.<br /><br />">
    </asp:CompareValidator>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ivy
    Ivy avatar
    30 posts
    Member since:
    Feb 2013

    Posted 23 Apr 2013 Link to this post

    Hi princy Is it possible to display an alert?
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Apr 2013 Link to this post

    Hi,

    If you want to display an alert, you can attach the OnDateSelected client event to the second RadMonthYearPicker and try the following JavaScript.

    JavaScript:
    <script type="text/javascript">
        function OnDateSelected(sender, args) {
            var Month1 = $find('<%=RadMonthYearPicker1.ClientID %>');
            var date1 = Month1.get_dateInput().get_selectedDate().getMonth();
            var date2 = sender.get_dateInput().get_selectedDate().getMonth();
            if (date2 < date1) {
                alert("The second date must be after the first one");
                sender.clear();
            }
        }
    </script>

    Thanks,
    Princy.
Back to Top