I wish to use a jQuery plugin in SharePoint. Currentley I have jQuery added to each page via a custom master page.
<script src="/Style Library/js/jquery-1.6.4.min.js" type="text/javascript"></script>
This can be found in the head section of the page.
I have created a web part. This web part needs jQuery to run. I add jQuery again and the requried plugin as below:
protected override void CreateChildControls()
{
Control control = Page.LoadControl(_ascxPath);
Controls.Add(control);
ScriptLink.Register(Page, "/_Layouts/js/jquery-1.7.1.min.js", false);
ScriptLink.Register(Page, "/_Layouts/js/jquery.dataTables.min.js", false);
}
The masterpage jQuery is being loaded after the web part. This is causing the plugin not work. If I remove the ScriptLink.Register(Page, "/_Layouts/js/jquery-1.7.1.min.js", false);
I get jQuery us not defined.
If I remove jQuery from my master page it all works.
How can I get the jQuery in the masterpage to load before any other scripts being added to the page?
Updated I have updated the code to be as follows:
protected override void CreateChildControls()
{
Control control = Page.LoadControl(_ascxPath);
Controls.Add(control);
}
and
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
ScriptLink.Register(Page, "/_Layouts/js/jquery-1.7.1.min.js", false);
ScriptLink.Register(Page, "/_Layouts/js/jquery.dataTables.min.js", false);
}
Both are loaded on the page as can be seen by IE Dev Tool Bar.
The problem still seems that the master page jquery is loaded after as the same error is occuring. Removing ScriptLink.Register(Page, "/_Layouts/js/jquery-1.7.1.min.js", false);
I get told that jQuery is not valid. It however can be seen in IE Dev Tool Bar.