jQuery now officially part of the .NET developer’s toolbox

You may have read that from John Resig or Scott Guthrie. I’m very excited to announce that Microsoft has decided to ship, adopt and support using jQuery on top of ASP.NET. This may come as a surprise to some of you but I hope you’ll agree with me that it makes total sense. jQuery is a fantastic JavaScript library that focuses on DOM querying and manipulation, whereas the Microsoft Ajax Library focuses on building reusable components and interacting with ASP.NET web services.

A lot has been written already on this new partnership so I’ll just go ahead and show some code that hopefully will show how great jQuery and ASP.NET AJAX work together.

As my first piece of code using both frameworks, I’ve built a very simple plug-in for jQuery that instantiates a specific control on all elements in a jQuery result set. Here’s the full code for the plug-in:

jQuery.fn.create = function(type, properties, events) {
    return this.each(function() {
        Sys.Component.create(type, properties, events, {}, this);
    });
};
And here’s how you can use it to create instances of a (pretty lame) sample behavior to limits the number of characters in all text inputs with a specific class on them:
$("input[type=text].nomorethantwenty")
    .create(Bleroy.Sample.CharCount, { maxLength: 20 });

This is the kind of super-simple code that we hope will make your life easier as an ASP.NET developer.

More of that stuff later…

I’m super-excited about this. How about you?

The sample code for this post:
http://weblogs.asp.net/blogs/bleroy/Samples/jQueryMicrosoftAjax.zip

The original announcement by John Resig:
http://jquery.com/blog/2008/09/28/jquery-microsoft-nokia/
and Scott Guthrie:
http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx

Q/A about the partnership:
http://cooney.typepad.com/lauren_cooneys_blog/2008/09/jquery-and-microsoft-the-qa.html

And here’s some cool code from Scott Hanselman:
http://www.hanselman.com/blog/jQueryToShipWithASPNETMVCAndVisualStudio.aspx

And this older post where I show how to use the ScriptManager with jQuery (and without Microsoft Ajax):
Using ScriptManager with other frameworks

25 Comments

  • The "Evil Empire" is turning good? Cool :D

  • Hi ,

    This is cool. Really its going to help a lot with client side programming which is going to be more futristic.
    Thanks for the post

  • Betrand - This is really exciting - I'm really glad to see that you're opting to use jQuery instead of building your own replacement to provide similar functionality.

    My hope is that some of the new features in 4.0 which sound exciting can be decoupled from the older Ajax libs which should provide a good way back into the MS Ajax stacks for some who've uhm left the fold. :-}

  • This is great news - I've been using Jquery alongside asp.net for a good while now, and it'll be great to have inbuilt intellisense support in VWD!

    Is this the last nail in the coffin for the AJAX TOOLKIT?

  • jQuery is a rich javascript library , i've use it in my latest project which i developed using asp.net ,.. it is easy to integrate with your code and easy to understand ..

  • What will happen to the parts of current MS librairies that overlap with jQuery such as the ajax control toolkit animation framework ?

  • What an excellent news !

    When I saw the first bits of ASP.net futures, I say to myself that ASP.net Ajax is trying to copy jquery, it was yet a good things for JavaScript developper using ASP.net.



    But 3 questions :

    - Does that mean that all Ms Ajax project will require jquery ? Will it be possible to use UdpatePanel without jquery ? If so, some function won't be duplicated ?
    I hope all Ms Ajax project require jquery !


    - How would you distribute jquery ? Will it be a ressource on an assembly ? or just a file added by a template project ?


    - When ? When can we see the new ASP.net Ajax library coupled with jquery ? when does it will be RTM ? with ASP.net 4 ?

  • Thanks a lot! Jquery is the most outstanding javascript framework i have ever used. This is really really exciting. Jquery rocks!

  • What's with all this listening and being responsive to developers? What have you done with the real Microsoft? Is it tied up in the broom closet? Kidding aside, this may go down as one of the greatest decisions in ASP.NET history. Thanks, Thanks, Thanks... Very nice work.

  • @Rick: working on that :)

    @Paul: not at all. Actually, the Toolkit is getting more resources than ever from Microsoft, as well as new controls (got a new submission yesterday actually).

    @mareek: that remains to be decided but we might want to avoid taking the full jQuery dependancy for all of the existing toolkit. We're not going to prevent contributors from using it starting now, but we need to keep the existing animation in there for back compat. Still figuring out the details.

    @cyrilcs: no, MS Ajax will not take a dependancy on jQuery, and UpdatePanel will be usable without jQuery. What we'll do is provide some simple integration points such as what I describe in this post.
    For the moment we'll distribute it as a file in the template projects. Resource-based is a possibility but considering the rate of releases from jQuery (about 10 releases a year) it might make it more difficult for people to upgrade. Components that want to take a dependency may need resources but the versioning might be tricky. We'll see.
    We're shooting for 4.0 but jQuery already works great with 3.5 SP1 and even earlier versions.

    @Chris: hush, please lower your voice, they might hear you.

  • First off. "Tales from the Evil Empire" is an awesome title!

    I can't comment much on the addition of jquery,I am just now diving into ASP.NET. But I can only see good things. Can't wait to see what kinds of apps are created with the new addition to the framework.

  • Have you decided yet how you'll handle updates to the jQuery library? Will they eventually be updated via hotfixes or service packs? I worry that thousands of ASP.NET web projects will be frozen at jQuery 1.2.6. ;)

  • Yep, love it. Good choice (of framework and strategic).

  • it's so excellent,jquery is a cool.i hope using in asp.net is firendly.

  • This is great. This is smart - with so many of the responses on the Roadmap thread on the ASP.NET forums referring to what jQuery does and how it should be duplicated in MS AJAX, this makes too much sense!

    These are decisions usually made by start-up types, nimble, quicky adapting makin it happen types - not multi-billion dollar conglomerates that hold 20+ people staff meetings over what copy paper to purchase! (I've lived in this environment .

    This is solid demonstration (amongst many other other initiatives) that MS wants to lead the market with its developers in tow.

    With these type of decisions being made, I have no doubt that MS can be a leader and us developers benefiting along with them!

  • Thank-you!!! This calls for a celebration, where can I send the beer?

  • @Adam: I'll be at PDC. Will you?


  • It's a sad, sad day when Microsoft decides to abandon its superior development efforts in favor of shipping trash from the open source community with Visual Studio.

    Not one to have bashed Microsoft in the past simply for the sake of doing so and also one experienced enough to not be easily impressed with open source trinkets, I must differ with the majority of the other submitted comments - Microsoft's AJAX functionality was far more impressive than that of lukewarm efforts like jQuery and a much more sound foundation upon which to build upon.

    I look forward to the day Microsoft decides to stop minimizing its distractions and once again begins kicking ass, rather than wasting time with the meanderings of hobbyists...

  • Best server side framework (asp.net) now ships with the best client side library (jQuery) to create the ultimate platform for web development.

    Thanks Guys!
    You Rock!

  • @Joe: we're not abandoning anything.

  • Joe i think you're missing the point. The whole asp.net ajax framework will still be in place but they will utilize jquery instead of compete against it. I see asp.net ajax as the framework where as jquery is more about dom manipulation and making it easier for us to create our extenders.


  • No, sorry. I'm not missing the point, but I do think it funny that you believe anyone need 'compete' against open source. My customers want nothing to do with open source. Period. Microsoft has more developers than the population of many mid-Western towns. That they couldn't blow the doors off of jQuery instead of taking the easy way out, rolling over and playing dead? Please...

  • @Joe: how this is the "easy way out" eludes me completely :)
    But I'd be interested in discussing with you the business needs of your customers and whether we could either find other technical ways of achieving your requirements or explain how what really counts here is Microsoft support. You can contact me at bleroy at Microsoft.

  • I converted the example to .net 3.5. When I run your example in Firefox, nothing happens, when I run it in IE I get: Microsoft JScript runtime error: Object expected

  • @ra170: Sorry to hear that. Not sure what's going on here. Feel free to send me a zip file with your site at bleroy at microsoft and I'll have a look.

Comments have been disabled for this content.