views:

88

answers:

5

Can I avoid using MS AJAX completely while developing ASP.NET Webforms applications and use jQuery/jQuery Tools instead?

jQuery seems to be much snappier, has better community, extremely small file size (24kb). It's also seems like an obvious choice for ASP.NET MVC development.

But what about Webforms? I really would rather not use AJAX Tools that comes with Visual Studio 2010. Can jQuery provide me with everything that default AJAX controls have to offer?

Thanks!

A: 

JQuery is built into visual studio 2010.

ironpaw
To support MVC. Utterly fails to address the question
Murph
+3  A: 

Yes. You can. But you need to use many jquery plugins for different functionality.

In one of our project (asp.net webforms), initially we are using MS Ajax. Now we are slowly moving to jquery with success.

Krunal
That's good to hear. I have 2 jQuery plugins that I will definitely be using: jQuery Tools for Validation and HighCharts JS for Charting. And even then it is significantly less "bloated" than similar controls in MS AJAX.
Silence of 2012
@Rihanna.Rain - now a days, microsoft officially supports jquery and jquery community is powerful enough to address all functionality that MS Ajax have.
Krunal
+3  A: 

That depends on the development model you require. jQuery requires using Web services for communication, while MS AJAX can work with implicit postbacks. Although the latter is handy for rapid development, the use of Web Services for data communication is better practice.

Most MS AJAX controls can be mimicked by using different jQuery libraries.

Prutswonder
+2  A: 

Short answer: Yes. And as ironpaw's answer hints at, Microsoft endorses this.

The only gotcha is that, as your probably know, with Webforms you can not control what client side ID your controls will get, making selection via $('#id') cumbersome.

I usually get around this with either using css classes for selection, or getting the ClientID property of controls in codebehind when needed (for example, when I need to reference a dynamically created control in a repeater).

Legogris
The id selection can be done using the `$("[id$='YOURID']")` selector.
Prutswonder
@Prutswonder: Good one. It's so obvious when you say it, but for some reason it never occurred to me. When several controls share the same server ID (for example with a Repeater or similar), fetching the client ID or e.g. selecting n:th child would still be needed though.
Legogris
+5  A: 

Can you use jQuery with webforms? Yes, that's not a problem - at the end of the day the whole webforms setup generates HTML web pages and hence jQuery can manipulate those.

Can jQuery provide everything the default AJAX controls provide - hmmm, yes in theory because ultimately all those are doing are a) manipulating the DOM and b) making out of band calls to the server. In practice you're going to be giving up some ease of use and you're going to have to do rather more work yourself.

The biggest problem - at least with apps running prior to .NET 4.0 - is that the IDs generated for server controls are, erm, interesting. If you can do everything you need in jQuery without reference to a control ID (if you can use classes or look for control types) you're away and running but if you need to be explicit about an ID you're going to be stressed unless you can use .NET 4.0

I've got code that mixes bits of the two (dynamic data sites that use the jQueryUI calendar as its vastly better than the toolkit one) and would certainly contemplate using more jQuery stuff in forms apps.

Murph
you can use the "ends with" attribute selector for server controls:`$("[ID$=myControl]")`
dave thieben
Neat, jQuery continues to impress
Murph
And indeed I have just got to a point where I need to do exactly this so although not a searched for answer distinctly a useful consequence of participating (-:
Murph