DatePicker is not fully disposed

0 Answers 24 Views
Calendar DateTimePicker
Petr
Top achievements
Rank 1
Iron
Petr asked on 16 Feb 2024, 09:36 AM
I have RadDatePicker in detail window for grid. I need to modify background color dynamically so I added new script to Calender like this:
datePicker.Calendar.ClientEvents.OnLoad = initMethodName;
Now I noticed that calendar is never destroyed from page. If I close detail window and open it again then initialization method is called twice.
It looks that table element with id "<ctrl_name>_calendar" is always there and never unloaded.

Can you help me how to dispose this object or remove event from it?

Thank you.
Rumen
Telerik team
commented on 19 Feb 2024, 10:53 AM

Hi Petr,

You can use the remove_load method to detach the OnLoad event: 

 

                <script>
                    function initMethodName(sender, args) {
                        sender.remove_load(initMethodName);
                    }

                    window.onbeforeunload = function () {
                        detachCalendarEvents();
                    };

                    function detachCalendarEvents() {
                        var datePicker = $find("<%= RadDatePicker1.ClientID %>"); // Adjust the ID accordingly
                        if (datePicker && datePicker.get_calendar()) {
                            datePicker.get_calendar().remove_load(initMethodName); // Assuming remove_load is a valid method
                        }
                    }
                </script>

 

If you are unable to solve the problem and it persists, please isolate it in a simple runnable project and send it for examination via a support ticket. 
Petr
Top achievements
Rank 1
Iron
commented on 20 Feb 2024, 07:40 AM

It works!

Thanks for your help.

No answers yet. Maybe you can help?

Tags
Calendar DateTimePicker
Asked by
Petr
Top achievements
Rank 1
Iron
Share this question
or