Question

Microsoft recently announced that the Javascript/HTML DOM library jQuery will be integrated into the ASP.NET MVC framework and into ASP.NET / Visual Studio.

What is the best practice or strategy adopting jQuery using ASP.NET 2.0? I'd like to prepare a large, existing ASP.NET Web Application (not MVC) for jQuery. How would I deal with versioning and related issues?

Are the any caveats integrating jQuery and ASP.NET Ajax? Or 3rd party components like Telerik or Intersoft controls?

Was it helpful?

Solution

For me, problems arise when using UpdatePanels and jQuery (no problem with MVC, which doesn't have a Page Life-Cycle and is truly stateless). For instance, the useful jQuery idiom


$(function() {
  // some actions
});

used to enhance your DOM or attach events to the DOM elements may not interact very well with the ASP.NET PostBack model if there are UpdatePanels in the page. By now, I circumvent it with the following code snippet


if (Sys.WebForms.PageRequestManager) {
  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function() {
    $('#updateListView1').trigger("gridLoaded");
  });
}
where gridLoaded will be the replacement of $(document).ready.

I think you have to take extra care and know very well the ASP.NET Page/Controls Life-Cycle in order to mix both technologies.

OTHER TIPS

There's a small issue which is mentioned by David Ward here: http://encosia.com/2008/09/28/avoid-this-tricky-conflict-between-aspnet-ajax-and-jquery/

But there should not be any major concerns about integrating jQuery into an existing application, you wouldn't notice major advantages unless you're planning a lot of updating/ reworking of existing code to take advantages of jQuerys power.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top