OnClientLoad calls a script before it is loaded

3 posts, 0 answers
  1. Ilya
    Ilya avatar
    3 posts
    Member since:
    Jun 2011

    Posted 04 Sep 2013 Link to this post

    I have a user control with a RadListBox in it. The Page_Load event of the user control calls ScriptManager.RegisterClientScript to register a js file. The RadListBox has an OnClientLoad property referencing a function in the js file.

    When I load the page with the user control I get a script error because the js file isn't loaded yet. But how can that be? RegisterClientScript puts a script tag in the head tag and OnClientLoad should only fire once the page is loaded. And when the page is loaded shouldn't the script tag already have been processed?

    After that initial error everything seems to work ok because by then the script is finally loaded.

    I tried putting the reference to the file directly into page that hosts the control but I still get the same error.
  2. Ilya
    Ilya avatar
    3 posts
    Member since:
    Jun 2011

    Posted 05 Sep 2013 Link to this post

    Ok, I had it wrong. It's not OnClientLoad that gets called. It's the Sys.Application.add_init block that initializes the RAD controls properties such as event handlers that gets called. It tries to assign an event handler but the function it references isn't loaded yet because it's in a script file.

    So how do I include a script file in my user control so that it is loaded before Sys.Application.add_init gets called?
  3. Ilya
    Ilya avatar
    3 posts
    Member since:
    Jun 2011

    Posted 05 Sep 2013 Link to this post

    Ok, found the solutions in this post:
    http://encosia.com/updated-your-webconfig-but-sys-is-still-undefined/

    Had to include a reference to my script in the <Scripts> tag of the ScriptManager on the main page.
Back to Top