Using JQuery in an AJAX control and avoiding conflicts
Posted
by
Rich Andrews
on Stack Overflow
See other posts from Stack Overflow
or by Rich Andrews
Published on 2011-02-22T23:20:39Z
Indexed on
2011/02/22
23:24 UTC
Read the original article
Hit count: 235
Hi,
I am using JQuery within a custom AJAX user control (part of a home grown toolkit) and I need to ensure that JQuery is present on the hosting page. There can be multiple instances of the control on a page and some controls may need to use different versions of JQuery.
At the moment I am using the following code to load in JQuery when the control initializes...
Page.ClientScript.RegisterClientScriptInclude(Page.GetType(), "jquery-1.4.4.min.js", this.ResolveUrl("TextControlPlugin/lib/jquery-1.4.4.min.js"));
This works because the scriptmanager handles not putting multiple copies of the same script into he page.
Problems...
- I cannot use JQuery statically in the calling page (I may not have a control on the page but need to use JQuery)
- The scriptmanager appears to handle only duplicate URL's and I will need to deploy it from potentially 2 different URL's (the calling page's copy and the controls copy)
So, is there a way to isolate a version of JQuery to the context of my control that doesnt interfear with any use of JQuery from the calling page? The developer writing the page may not have access to the internals of the control.
I have looked at JQuery.noConflict() but cannot seem to get it to work correctly - I believe I'm having problems with the order in which the scripts are injected into the page - I keep getting JQuery is undefined errors.
Any help would be much appreciated
© Stack Overflow or respective owner