I have two SharePoint features, each implemented identically (see below), that add controls to a delegate control in the header of my pages. One of the controls depends on the other (one is the jQuery library, and the other depends upon jQuery), however, when the controls are rendered, the order of the controls is incorrect. How do I specify the order that these controls are rendered in?
The control (both are identical, except that they reference a different .js file):
<%@ Control ClassName="MyScriptControl" %>
<script type="text/javascript" src="/_layouts/MyScript.js"></script>
feature.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="AA9D59AC-D53E-4338-9B52-CD39F2A8C31A"
ActivateOnDefault="true"
Title="My Feature"
Description="Does something."
Scope="Site" Version="1.0.0.0"
Hidden="FALSE"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="MyFeature\Elements.xml" />
</ElementManifests>
</Feature>
Elements.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"
Id="24A4BB9A-9636-4a73-B3A5-35661DE19902">
<Control Id="AdditionalPageHead"
ControlSrc="~/_controltemplates/MyControl.ascx" />
</Elements>
The output on the page (jQuery is deployed before DependsOnjQuery):
<script type="text/javascript" src="/_layouts/DependsOnjQuery.js"></script>
<script type="text/javascript" src="/_layouts/jQuery.min.js"></script>
I want MyControl1.js to render before MyControl2.js.
I was able to get this to work by adding a second DelegateControl to the header of my masterpage, and adding jQuery to that delegate. This way, I can make sure that jQuery will always load before everything else, without having to write some logic to delay the loading of my dependant libraries.
<SharePoint:DelegateControl runat="server" ControlId="jQueryDelegate" AllowMultipleControls="true"/>
<SharePoint:DelegateControl runat="server" ControlId="AdditionalPageHead" AllowMultipleControls="true"/>