views:

28

answers:

2

I am successfully including a javascript resource by calling ScriptManager.RegisterClientScriptResource at the end of OnPreRender in my custom control. However, the resulting script tag is being included before the automatically included script tags that define things like Type and Sys which my script depends on. I thought they were defined in the order that they are included but I can't include my script any later then I am. How can I control the order in which the script tags are included?

A: 

Try to do this on OnLoad, not on OnPreRender

abatishchev
I just tried this again and there is no change.
drs9222
+3  A: 

Your parent page must that contains the custom control must have ScriptManager and make sure the custom control you add is placed after the ScriptManager Tag. Sometimes its best just to place the ScriptManager tag in the MasterPage.

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
.......
<uc:YourControl ID= "YC" runat = "server" />
Robert
I have a ScriptManager defined as the first thing within the form on the master page.
drs9222
What kind of control is it? Does it use the ajax toolkit?
Robert
It is a UserControl and we do not use the ajax toolkit.
drs9222
Place a SciptManagerProxy in your custom control and this should fix it: <asp:ScriptManagerProxy> <Scripts> <asp:ScriptReference Path="yourscript.js" /> </Scripts> </asp:ScriptManagerProxy>
Robert
Interesting, I had just finishing putting one in when I saw this last comment. I just tested it and it did work! However, I'm not sure if I did what you meant. I added the ScriptManagerProxy with a ScriptReference, using Assembly and Name, and removed my RegisterClientScriptResource call.
drs9222
Oh you changed it on me :)
drs9222
Sorry bout the change. I hoped everything works out.
Robert
Oh it works now! I am curious though, every example I can find does it in the code behind and without the proxy. Do you know why this changes the order? Is it a UserControl thing? I didn't think there was that big of a difference, after all they still derive from Control.
drs9222