开发者

Using JQuery in an AJAX control and avoiding conflicts

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 fro开发者_运维百科m 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


Would there be a problem just taking a dependency on jQuery and putting it in your base MasterPage? This way, it would always be ensured to be in the page.

I'd recommend going for only one version of jQuery too as it will get confusing very quickly as to which variable refers to which version of jQuery. Passing true to $.noConflict(true) will assign what jQuery references to _jQuery and _$.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜