ASP.NET master pages order of adding scripts

1.8k views Asked by At

I have a master page that adds the jquery library via a registerclientscriptinclude:

Page.ClientScript.RegisterClientScriptInclude(this.GetType(), 
    "JQuery", 
    Page.ResolveUrl("~/Scripts/jquery-1.2.6.min.js"));

In a page that uses that master page I want to include a script that depends on jquery:

Page.ClientScript.RegisterClientScriptInclude(this.GetType(), 
    "jqplugin1", 
    Page.ResolveUrl("~/Scripts/jquery.plugin1.compressed.js"));

This causes a problem because the page's client scripts are written first and then the master pages client scripts (causing the plugin to complain that "jquery" is undefined).

Is there anyway to control the ordering of client script includes? Alternatively any recommendation on how best to control this (temporarily the master page is just including everything... but that's not going to work long term).

2

There are 2 answers

1
np-hard On BEST ANSWER

since master page is like a control embedded in a page, you can add these scripts towards the end of the page cycle, the control would fire first and then page, so your page would be fine.

2
mbillard On

You could re-include the jQuery library in the page, if it's already there it will simply override it, if not it will be added.