This is a migrated thread and some comments may be shown as answers.

RadDatePicker OnDateSelected Loop

1 Answer 138 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 14 Jan 2010, 12:00 AM
I have a RadDatePicker that if the user changes the date I have a confirm message to ask if the want to change the date.
If they click no I want to change the date back to its original value.
In my java script I have
var datepicker = $find("datePicker");
datepicker.set_selectedDate(args._oldDate);

when I set the selected date the function is called again and I am stuck in an Infinate loop since everytime I am setting the selected date in javascript the function is calling its self. I just want it so that if the user clicks no that the date will not change. I haven't been able to find anything on this site to fix it.

Thanks

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Jan 2010, 05:45 AM
Hello Ryan,

Use a global variable in order to check whether it is entering for the second time in DateSelected event handler as shown below.

JavaScript:
 
<script type="text/javascript"
    var check = false
    function OnDateSelected(sender, args) { 
        if (!check) { 
            if (!confirm('do you want to change the date ?')) { 
                check = true
                sender.set_selectedDate(args.get_oldDate()); 
            } 
            else { 
                sender.set_selectedDate(args.get_newDate()); 
            } 
        } 
        check = false
    } 
</script> 
[Attach 'OnDateSelected' client event to RadDatePicker.]

-Shinu.
Tags
Calendar
Asked by
Ryan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or