I have a highly customized page that uses about 3 update panels. I am just starting to integrate some jQuery(), but I'm not sure how to implement any function that needs to be called within the $().ready(callback) .
I would prefer to write this code server-side and have it propagate to client-side. Basically, I mean that I would like to use the ScriptManager to Execute my script.
I have seen a couple things online, but I have not really gotten anything to work.
I also read that you can just put the callback code from ready() within the RegisterStartupScript() code blocks. I did not have success with this either. I get errors thrown in ScriptResource.asx (or something like that).
$().ready() is the jquery version ScriptManager.RegisterStarupScript.
if your jQuery binds to controls in the update panel, then you need to rebind after an update. you shoudl also unbind the old controls or you wll have a memory leak.
if you are using an update panel, you can also register your jquery with the ms ajax client events handles see PageManager. these routines are a lot harder then jquery though. If you are using jQuery I'd drop the update panel and use the jQuery version.
$(document).ready() plays well with the ScriptManager and UpdatePanel. No reason to avoid it.
If what you need is to execute something on the initial page load and every UpdatePanel refresh, put that code in a JavaScript function named pageLoad(). It will automatically be executed in both of those situations.
dvdrgods
Member
3 Points
38 Posts
UpdatePanels and $().ready() . How to get this to work.
Jul 01, 2010 11:19 PM|LINK
Hello.
I have a highly customized page that uses about 3 update panels. I am just starting to integrate some jQuery(), but I'm not sure how to implement any function that needs to be called within the $().ready(callback) .
I would prefer to write this code server-side and have it propagate to client-side. Basically, I mean that I would like to use the ScriptManager to Execute my script.
I have seen a couple things online, but I have not really gotten anything to work.
I have tried code similar to http://blog.dreamlabsolutions.com/post/2009/02/24/jQuery-document-ready-and-ASP-NET-Ajax-asynchronous-postback.aspx . but with no success. I wrote this code in the middle of a web-user control and nothing ever seemed to get called.
I also read that you can just put the callback code from ready() within the RegisterStartupScript() code blocks. I did not have success with this either. I get errors thrown in ScriptResource.asx (or something like that).
Is there something I'm missing?
Any suggestions?
Thanks,
stringa
sandy060583
Star
8714 Points
1624 Posts
Re: UpdatePanels and $().ready() . How to get this to work.
Jul 02, 2010 06:41 AM|LINK
post some code please ??
Ramani Sandeep (My Blog)
(MCTS, MCC-2011)
bruce (sqlwo...
All-Star
36852 Points
5446 Posts
Re: UpdatePanels and $().ready() . How to get this to work.
Jul 03, 2010 03:34 AM|LINK
$().ready() is the jquery version ScriptManager.RegisterStarupScript.
if your jQuery binds to controls in the update panel, then you need to rebind after an update. you shoudl also unbind the old controls or you wll have a memory leak.
if you are using an update panel, you can also register your jquery with the ms ajax client events handles see PageManager. these routines are a lot harder then jquery though. If you are using jQuery I'd drop the update panel and use the jQuery version.
gt1329a
All-Star
15377 Points
2501 Posts
ASPInsiders
MVP
Re: UpdatePanels and $().ready() . How to get this to work.
Jul 03, 2010 08:06 AM|LINK
$(document).ready() plays well with the ScriptManager and UpdatePanel. No reason to avoid it.
If what you need is to execute something on the initial page load and every UpdatePanel refresh, put that code in a JavaScript function named pageLoad(). It will automatically be executed in both of those situations.
More information: http://encosia.com/2009/03/25/document-ready-and-pageload-are-not-the-same/
A guide to combining jQuery and ASP.NET: jQuery for the ASP.NET developer