Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Webforms with jQuery?

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!

like image 220
Sahat Yalkabov Avatar asked Jul 14 '10 06:07

Sahat Yalkabov


4 Answers

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.

like image 96
Murph Avatar answered Oct 01 '22 18:10

Murph


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.

like image 45
Krunal Avatar answered Oct 01 '22 19:10

Krunal


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.

like image 44
Prutswonder Avatar answered Oct 01 '22 17:10

Prutswonder


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).

like image 21
Legogris Avatar answered Oct 01 '22 18:10

Legogris