This blog post will be in English, I think that this topic could be interesting for many devs also outside Slovakia ;)
Yesterday, colleague of mine had trouble with running javascript when page loads and do some things with object in browser. This browser was IE8 and I think (we didn't tried that out, i'm sorry) that other browsers behave differently according their implementations.
When you want to manipulate with Telerik objects, you are probably using $find("control clent id") to find particular control and then run some methods or set some properties. If not, you should, because only then you can access javascript methods that Telerik created, the client side api of every control.
So far, so good. This approach works when your javascript runs as event handler of some control, as a response to user action (button click, etc.). But if you would try to run code on for example page load event, $find wont work. (This also applies, when you add your javascript to rendered page via Page.ClientScript.RegisterClientScriptBlock in code behind, because this code is also placed in page load event)
First question is, why is this so? Everything should be fine, but isn't.
The answer is, because page load event is fired too soon and although the html did arive, objects aren't in memory, in DOM.
So, what we can do about this kind of problem?
This particular problem can be solved quite easily. :) We need to find some event that is fired when everything is loaded. At first, my guess was, we should use (because Telerik is using MS AJAX library and jQuery) $(document).ready(function() from jQuery, but this event is also fired too soon. I suppose, that at first, jQuery is processed and than MS AJAX. After s while of searching the web it turned out, that we should use MS AJAX brother event, Sys.Application.add_load.
So, to successfully fire some javascript function, you should add this method anywhere in <script> </script> block :
Sys.Application.add_load(method name to call);
If you want to know more, read these related articles :
http://blogs.telerik.com/dimodimov/posts/08-12-13/don_t_use_body_onload_in_asp_net_ajax_websites.aspx
http://www.telerik.com/community/forums/aspnet-ajax/input/find-not-working-with-ie-8.aspx
http://docs.jquery.com/Tutorials:How_jQuery_Works - one of many tutorials, please read part Launching Code on Document Ready
In case of any questions, you can reach me via mail : dusan at rostacik.net or via twitter : @rostacik.