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