This is a migrated thread and some comments may be shown as answers.

ScriptRegistrar scripts rendering order issue

4 Answers 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Aleksey Karlin
Top achievements
Rank 1
Aleksey Karlin asked on 15 Sep 2011, 07:06 PM
I have an issue with scripts order rendered by ScriptRegistrar. How is it supposed to register base scripts (like jQuery) in the layout page and based on them scripts (like jQuery.validation) in a view?

_Layout.chtml:
@(Html.Telerik().ScriptRegistrar().jQuery(false).jQueryValidation(false)
        .DefaultGroup(group =>
            group.Add("jquery-1.6.3.min.js")
                 .Add("jquery-ui-1.8.16.min.js")
                 .Add("modernizr-1.7.min.js")
                 .Add("jquery.query-2.1.7.js")))

Index.chtml:
@{
    Html.Telerik().ScriptRegistrar().DefaultGroup(group =>
                                                  group.Add("jquery.validate.min.js")
                                                      .Add("jquery.validate.unobtrusive.js"));
}

I got validation library loaded first, and only then jQuery one. In this case scripts don't work properly of course.

4 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 16 Sep 2011, 04:16 PM
Hi Aleksey,

The scripts will be registered in order only if the ScriptRegistrar in the layout page comes before RenderBody (or the respective RenderSection).

The order is the same as if you combine the layout and content views into a single file.

Kind regards,
Tsvetomir Tsonev
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
0
Aleksey Karlin
Top achievements
Rank 1
answered on 17 Sep 2011, 09:40 PM
But what if I need to output scripts right before end body tag, which is located in the layout page. RenderBody is in charge of drawing some specific page's content and is located much earlier on the page. How can I follow scripts registering practices (see "ScriptRegistrar declaration in Site.master" on this page) and have my scripts rendered in the right order in this case?
0
Accepted
T. Tsonev
Telerik team
answered on 19 Sep 2011, 09:00 AM
Hi Aleksey,

You have to either:
    a) register all the scripts in the master page or
    b) add a section before the script registrar and use it to register the scripts

The second approach is more flexible and allows you to register additional scripts in the order you desire.

Best regards,
Tsvetomir Tsonev
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
0
Aleksey Karlin
Top achievements
Rank 1
answered on 19 Sep 2011, 05:34 PM
The second approach is fine by me, thanks.
Tags
General Discussions
Asked by
Aleksey Karlin
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Aleksey Karlin
Top achievements
Rank 1
Share this question
or