Geeks With Blogs

News
Steve Clements .Net and then some....

OK, so for some reason you have a mega mashup solution with ASP.net AJAX, jQuery and web forms. 

Perhaps you are just on the migration from AjaxControlToolkit to the jQuery UI framework – who knows!!

Anyway, the problem is that when you post back with something like an UpdatePanel, you will find that your nicely setup jQuery stuff, like the datepicker for example will no longer work.

You may have something like this…

  1. $(document).ready(function () {
  2.     $(".date-edit").datepicker({ dateFormat: "dd/mm/yy", firstDay: 1, showOtherMonths: true, selectOtherMonths: true });
  3. });

 

When you’re ASP.net UpdatePanel post back, you will find that your datepicker has gone.  Bugger!

Well you need to add this little gem to set it back up again once the UpdatePanel comes back to the page.

  1. var prm = Sys.WebForms.PageRequestManager.getInstance();
  2. prm.add_endRequest(function () {
  3.     $(".date-edit").datepicker({ dateFormat: "dd/mm/yy", firstDay: 1, showOtherMonths: true, selectOtherMonths: true });
  4. });

 

Or like me, you would have a javascript function, something like InitPage(); do all your work in there and call that on document.ready and endRequest.

Your choice…you have the power Smile

 

Share this post :
Posted on Monday, February 7, 2011 2:26 AM ASP.net AJAX , ASP.net , .NET 4.0 , jQuery | Back to top


Comments on this post: Setting jQuery after ASP.net AJAX partial post back

# re: Setting jQuery after ASP.net AJAX partial post back
Requesting Gravatar...
Thanks Steve...Very nice.
Left by sathiya on Sep 17, 2011 8:38 AM

# re: Setting jQuery after ASP.net AJAX partial post back
Requesting Gravatar...
Well, good solution. But take a look at this post http://jquerybyexample.blogspot.com/2010/07/jquery-does-not-work-properly-after.html.

This guy has explained 2 other methods as well and he had also posted about Datepicker and Ajax.

http://jquerybyexample.blogspot.com/2010/08/jquery-datepicker-does-not-work-after.html
Left by Vijay on Mar 26, 2012 10:47 AM

Your comment:
 (will show your gravatar)


Copyright © Steve Clements | Powered by: GeeksWithBlogs.net