set_cancel using Datepicker

4 posts, 0 answers
  1. Elgin
    Elgin avatar
    1 posts
    Member since:
    Dec 2011

    Posted 29 Feb 2012 Link to this post

    I am having an issue with set_cancel firing

     

     

    <telerik:RadDatePicker runat="server" ID="DateNeededDP">
    <
    ClientEvents OnDateSelected="DateSelected" />
    </
    telerik:RadDatePicker


    <telerik:RadDatePicker runat="server" ID="EffDateDP" >
    <
    ClientEvents OnDateSelected="DateSelected" />
    </
    telerik:RadDatePicker>

     

    <telerik:RadDatePicker runat="server" ID="EndDateDP">
    <
    ClientEvents OnDateSelected="DateSelected" />
    </
    telerik:RadDatePicker>

     

     

    function DateSelected(sender, eventArgs) {

        formdirty();

        var node = sender.get_id().substr(sender.get_id().indexOf("_MainContent_") + 13);

        if (node == "EndDateDP") {

            var datePicker = $find("<%= EffDateDP.ClientID %>");

            var effdate = datePicker.get_selectedDate();

            var enddate = sender.get_selectedDate();

            if (enddate <= effdate) { 
                        eventArgs.set_cancel(true);

                        alert("End Date must be greater than Effective Date");

                    }

            }

             if (node == "EffDateDP") {

            var datePicker = $find("<%= EndDateDP.ClientID %>");

            var enddate = datePicker.get_selectedDate();

            var effdate = sender.get_selectedDate();

            if (enddate <= effdate) { 
                        eventArgs.set_cancel(true);

                        alert("Effective Date must be less than End Date");

                    }

            }

        if (node == "DateNeededDP") { 
            var Neededdate = sender.get_selectedDate();

            var today = new Date();

            if (Neededdate < today) {

                        eventArgs.set_cancel(true);

                        alert("Needed Date must be greater than Today");

                    }

            }

    }


    The alerts fire correctly but it is not canceling the selected date.  And help would be great.

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

    Posted 01 Mar 2012 Link to this post

    Hello,

    For cancelling the selected date try the following code.
    JS:
    function DateSelected(sender, eventArgs)
    {
    sender.clear();
    }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. DonKitchen
    DonKitchen avatar
    92 posts
    Member since:
    Jul 2007

    Posted 13 Jul 2012 Link to this post

    That doesn't cancel (i.e. revert) the date.

    Is there a way to set_cancel and revert to the old value without another event firing?

    I'm trying to cancel a user's change and revert to the old (previous) value but am caught in a loop as the DateSelected event keeps firing when I set the date back to the old date.

    Here's an example.  What can I do to prevent this?  There doesn't seem to be a "changing" event for the Datepicker that works!

    function DateSelected(sender, args) {
     
                var go = window.confirm("Changing the start will cause all data to be reloaded. Do you wish to continue?");
     
                if (!go) {
                    var oldDate = args.get_oldDate();
                    sender.set_selectedDate(oldDate);  
                }
     
                args.set_cancel(!go);
            }
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Jul 2012 Link to this post

    Hello,

    Try the following to get the old date.
    JS:
    function DateSelected(sender, args)
     {
      var dt= args.get_oldValue();
     }

    Thanks,
    Princy.
Back to Top