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?
views:
28answers:
2I just tried this again and there is no change.
drs9222
2010-10-20 14:20:42
+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
2010-10-20 14:18:41
I have a ScriptManager defined as the first thing within the form on the master page.
drs9222
2010-10-20 14:22:38
Place a SciptManagerProxy in your custom control and this should fix it: <asp:ScriptManagerProxy> <Scripts> <asp:ScriptReference Path="yourscript.js" /> </Scripts> </asp:ScriptManagerProxy>
Robert
2010-10-20 14:30:50
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
2010-10-20 14:37:35
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
2010-10-20 14:46:38