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

OnClientLoad calls a script before it is loaded

2 Answers 51 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ilya
Top achievements
Rank 1
Ilya asked on 04 Sep 2013, 10:15 PM
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 Answers, 1 is accepted

Sort by
0
Ilya
Top achievements
Rank 1
answered on 05 Sep 2013, 02:50 PM
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?
0
Ilya
Top achievements
Rank 1
answered on 05 Sep 2013, 03:18 PM
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.
Tags
General Discussions
Asked by
Ilya
Top achievements
Rank 1
Answers by
Ilya
Top achievements
Rank 1
Share this question
or