+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Loading JS in an Assembly after jQuery loads

Loading JS in an Assembly after jQuery loads

5 posts, 0 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    25 Jul 2010
    Link to this post
    I have an assembly Im building that has javascript that needs to load AFTER jQuery...is that doable somehow?

    As in we assume jQuery is being loaded somewhere, but defer the loading of this script because it wont run without jQuery...
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    25 Jul 2010
    Link to this post
    Hi Steve,

    The Page renders from the top to the bottom, so it depends on how you will order your scripts if your are adding them declaratively. Another option is registering the scripts by using server side methods and events - Init, Load, PreRender.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    25 Jul 2010
    Link to this post
    The jQuery is loading in the ScriptManager, and the assembly is loading the script

    I think I might have gotten it with this...

    It at least loads, but getting some script errors from it
    string includeScript = Page.ClientScript.GetWebResourceUrl(this.GetType(), "Assembly.Control.Script.script.js");
                 
    Page.ClientScript.RegisterStartupScript(this.GetType(), "mycript", String.Format("<script src='{0}' type='text/javascript'></script>", includeScript));

    So it puts a <script tag at the bottom with the URL to the WebResource
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    26 Jul 2010
    Link to this post
    Hello Steve,

    Could you please tell us what kind of errors are you receiving? Make sure that you have added a web resource reference in the AssemblyInfo.cs file of your code library. Something like this:
    [assembly: WebResource("Sitefinity.Samples.Resources.JavaScriptFile.js","text/javascript")]


    Greetings,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    26 Jul 2010
    Link to this post
    Oh yeah, I have all that, it wasn't a sitefinity issue by any means, turns out the script was being registered twice and that was throwing an error.  So I just put a check beforehand...working great now

    Thanks :)
Register for webinar
5 posts, 0 answered