Javascript code does not work in Sitefinity

Posted by Community Admin on 03-Aug-2018 14:16

Javascript code does not work in Sitefinity

All Replies

Posted by Community Admin on 18-Oct-2012 00:00

I have some external JS files used by my master page and my user control. However, the jQuery code does not work at all. I tried using
<sf:JavaScriptEmbedControl runat="server" id="jsLink1" ScriptEmbedPosition="BeforeBodyEndTag"
        url="~/JS/scripts.js">
</sf:JavaScriptEmbedControl>


as well as using

<asp:ScriptManager ID="ScriptManager" runat="server" LoadScriptsBeforeUI="true"  >
    <Scripts>
        <asp:ScriptReference  Path="~/JS/scripts.js" ScriptMode="Debug" />
    </Scripts>
 </asp:ScriptManager>

as suggested by www.sitefinity.com/.../problems-getting-jquery-scripts-to-work-if-only-added-to-the-master-page. Neither of them has solved my problem.  All the JS files are successfully "GET" as shown by FireBug.

E.g. I set a breakpoint at the "jQuery(document).ready(function ($) " line and tried to step in. However the process paused at the  "jQuery(document).ready(function ($) " line,  and after I hit "step in", it  just exitted, leaving the rest of the initialization code untouched.

Any suggestions ?

Posted by Community Admin on 18-Oct-2012 00:00

Hey Yinfang,

You can find an example Masterpage here gist.github.com/3899224 which uses jQuery and it shows several options of including your own Javascript prior and after the jQuery is loaded. By using the sf:resourceFile tags we avoid jQuery conflicts and double loading of jQuery.

For some background reading, I suggest:
www.sitefinity.com/.../how-do-i-incorporate-jquery-into-a-master-page

and

www.sitefinity.com/.../2

Jochem

Posted by Community Admin on 18-Oct-2012 00:00

After I changed the order of JS files in between
<sf:JavaScriptEmbedControl> and </sf:JavaScriptEmbedControl>, the jQuery code works now. It seems that the order of loading JS files does matter, not like "#include" in C++ nor "import" in Java.

Posted by Community Admin on 18-Oct-2012 00:00

@YinFang
  Yes, fun...isn't it :/

Vote: www.telerik.com/.../pits.aspx

This thread is closed