SharePoint DelegateControl 渲染顺序

发布于 2024-07-14 06:11:14 字数 1486 浏览 7 评论 0原文

我有两个 SharePoint 功能,每个功能的实现都相同(见下文),它们将控件添加到页面标题中的委托控件。 其中一个控件依赖于另一个控件(一个是 jQuery 库,另一个依赖于 jQuery),但是,当呈现控件时,控件的顺序不正确。 如何指定这些控件的呈现顺序?

控件(两者相同,只是引用不同的 .js 文件):

<%@ 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>

页面上的输出(jQuery 在 DependsOnjQuery 之前部署):

<script type="text/javascript" src="/_layouts/DependsOnjQuery.js"></script>
<script type="text/javascript" src="/_layouts/jQuery.min.js"></script>

我希望 MyControl1.js 在 MyControl2.js 之前呈现。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

假面具 2024-07-21 06:11:14

我可以通过将第二个 DelegateControl 添加到母版页的标题并将 jQuery 添加到该委托来使其工作。 这样,我可以确保 jQuery 始终在其他所有内容之前加载,而无需编写一些逻辑来延迟加载我的依赖库。

<SharePoint:DelegateControl runat="server" ControlId="jQueryDelegate" AllowMultipleControls="true"/>
<SharePoint:DelegateControl runat="server" ControlId="AdditionalPageHead" AllowMultipleControls="true"/>

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"/>
云巢 2024-07-21 06:11:14

在我看来,Sequence 属性可以用来控制这些家伙的渲染顺序。 给你的 jQuery 控件一个 50 的序列,给你的 DependsOnjQuery 控件一个 100 的序列,你应该很好。

有关详细信息,请参阅 MSDN 上的委派控制文档

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.

浅语花开 2024-07-21 06:11:14

您是否尝试在脚本上设置 DEFER="DEFER" 属性?

这将告诉用户代理脚本应该等待页面加载并呈现,然后再加载脚本。

否则,您可以通过在一个脚本中设置一个变量来破解它,该变量在加载脚本时设置为 true。 在另一个中,您放置了测试脚本是否已加载的逻辑(考虑循环和超时方法),然后在加载两个脚本时调用您的逻辑。

不是很好,但是您需要某种逻辑来处理执行,而不仅仅是在脚本中内联运行方法。

致 nathan:委托中的序列用于确定要加载哪个委托控件。 这应该与所讨论的问题无关。 据我了解,JS 文件只是在恰好是委托控件的脚本上设置值。

did you try and set the DEFER="DEFER" attribute on the script.

that would tell the user agent that the script should wait for the page to load and render before it loads the script.

Else you could hack it by setting a variable at the one script, that is set to true when script is loaded. In the other you placed logic that tested (think loop and timeout method) if the script was loaded and then calls your logic when both scripts are loaded.

not very nice, but you need some kind of logic to handle execution, and not just run the methods inline in your script.

To nathan: sequences in delegates are used to determine which of the delegate controls to load. This should have nothing to do with the issue in question. As i understand it the JS files just set the value on a script that just happens to be a delegate control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文