views:

1311

answers:

9

We are planning to use the JQuery library to augment our client side JavaScript needs.

Are there any major issues in trying to use both ASP.Net AJAX and JQuery? Both libraries seem to use $ for special purposes. Are there any conflicts that we need to be aware of?

We also use Telerik controls that use ASP.Net AJAX.

TIA

+5  A: 

jQuery has a noConflict() method as a part of the core, but it then requires that you either use jQuery as your named function or something else of your choosing (instead of the dollar selector). However, I will say that the method is often dependent on the implementation of the "competing" library. I have tried to use it for a Ning social network (which used Dojo), and for Magento (which uses Prototype), and I could not get either to play right with jQuery. This is just my personal experience, and others have been very successful.

http://docs.jquery.com/Core/jQuery.noConflict

hal10001
+8  A: 

We have used ASP.NET Ajax, JQuery and Telerik components on a large project for quite a while and haven't had any issues

I would definitely recommend using JQuery

BlackTigerX
+3  A: 

The developers of ASP.NET Ajax took specific steps to make sure that the library could be used in conjunction with JQuery.

For example, the ATLAS CTP (the beta which became ASP.NET Atlas) used to have a $() function, but it was removed and replaced with $get().

Euro Micelli
Errhhh... They took steps to make sure ASP.NET AJAX worked with *prototype* in fact since at the time jQuery was an "obscure hobby project by this guy working for Mozilla" - while prototype powered 46% of all major websites in the world... ;)
Thomas Hansen
+1  A: 

I have been using ext which is another javascript framework with .net. It is far easier to use than old fashioned HTML form controls

<input type="text" id="whatever" />

Than using ASP.net form controls. You probably want to use the cool javascript framework form validation as opposed to the not so great built in .net validators too, but I guess that's down to your preference

If you do want to carry on using .net controls, remember that the ID generated in markup is different to what you define, so if you want to reference a control by id in JS use:

<%=MyControlId.ClientID%>
qui
+2  A: 

One downside is that server side controls can get renamed, depending on their containers. For example, you might have:

<asp:panel id="panel1" runat="server"></asp:panel>

This may be rendered to the page as:

<div id="ctl00$panel1"></div>

So if you write jQuery using $('#panel1') as a selector, it won't work. The way around this is to generate the id dynamically, eg:

 Dim js as String = "$('" & panel1.ClientID & "').whatever();"

This can make the javascript a bit unreadable, but it does work quite well. I work on a large web app using this method, and jQuery has saved us a TON of time, not to mention making the site look and work much better.

gregmac
Right. That is something one needs to be aware of it. In our web app, I have created a base page that exposes mechanism to register controls ids that you want to access client side and this cln is rendered as a JS object like MyId.MYpage.ClientId
rams
A better way around it for some situations is to use a selecter that finds controls with **id's that end in [someControlId]**, like this: $("[id$=someControlId]")
MGOwen
+2  A: 

For what it's worth, there is no conflict between jQuery's $ function and ASP.NET AJAX's $ prefixed shortcut functions ($get, $find, $create, etc). Just the same as using a variable f doesn't prevent you from using a variable named foo.

jQuery and ASP.NET AJAX work well together in the majority of cases. In the past year, the only time I've seen ASP.NET AJAX break jQuery code was this scenario with jDrawer. The workaround wasn't bad though.

Dave Ward
+1  A: 

A recent development related to this question:

Scott Guthrie posted on September 28th 2008 (see: http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx) that Microsoft will actually begin shipping JQuery with Visual Studio. MVC projects will include the library by default. Scott indicates that this is being done with the consent and encouragement of the JQuery team.

See the original post for full details.

Euro Micelli
saw that one. This should put to rest any doubts about the interoperability of ASP.Net AJAX and jQuery
rams
+1  A: 

Apparently, Telerik has begun adding jQuery to some of their RadControls, starting from release Q3.

I use both jQuery and RadControls, but haven't had the time to look any further into this entanglement...could swing both ways....
I have an omnius feeling that this entails more clusterf***, but that's just based on general experience with some of this and a little bit of that ;-)

Check out Atanas Korchev's blog at Telerik on just this subject :
http://blogs.telerik.com/AtanasKorchev/Posts/08-11-06/ASP_NET_Ajax_Controls_and_jQuery.aspx

and the best of luck to us all when MS, jQuery, Telerik, JP Morgan and McDonalds all mingle and mash upon our desktops... ;-)

Morten Bergfall
+1  A: 

I've used jQuery with ASP.NET Ajax as they both do different things well. I've never had an issue with using the two together. In fact, I get around the wierd ASP.NET id mishmash by using the super powerful jQuery selectors. By being able to select classes and sub-elements of elements (basically CSS) it makes it very easy to use.

BeaverProj

related questions