OnLoad or OnRendered events for Telerik Components?

1 Answer 41 Views
General Discussions Window
Johan
Top achievements
Rank 1
Iron
Iron
Johan asked on 26 Nov 2023, 07:32 PM

I'm in need for an OnRendered event (or similar) for a TelerikWindow component. Actually, it would be nice to have for all Telerik blazor components. I this particular case I need to know when a specific <div> is avaible to the browser DOM so that I can call some javascript interop on it. In this case I need to show I leaflet map in the modal window.

I solved it for now, using a javascript timeout of 0.1 second, but that is bad coding.

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 28 Nov 2023, 09:57 AM

Hello Johan,

Blazor doesn't provide such events natively and our components don't know when they have rendered either (except for the components with client-side rendering such as the Charts). So if we should expose such events, we need to do the same bad coding in the product itself. The coding may even be worse, because we will aim for more reliability and universal applicability.

When I have a similar task, my usual approach is:

  1. Raise a boolean flag in the Razor component, for example where you are showing the Window.
  2. Check and reset the flag value in OnAfterRenderAsync, execute a short Task.Delay() and then call the JavaScript. Depending on the exact situation, I may use setTimeout in the JavaScript as well.

Here is a REPL example.

Regards,
Dimo
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
Tags
General Discussions Window
Asked by
Johan
Top achievements
Rank 1
Iron
Iron
Answers by
Dimo
Telerik team
Share this question
or