Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharePoint DelegateControl Render Order

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.

like image 579
Kyle Trauberman Avatar asked Sep 15 '26 02:09

Kyle Trauberman


2 Answers

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"/>
like image 150
Kyle Trauberman Avatar answered Sep 18 '26 19:09

Kyle Trauberman


It looks to me like the Sequence attribute can be used to control the order in which these guys are rendered. Give your jQuery control a sequence of 50 and your DependsOnjQuery control a sequence of 100 and you should be good.

See the Delegate Control documentation on MSDN for more info.

like image 35
Nathan DeWitt Avatar answered Sep 18 '26 19:09

Nathan DeWitt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!