I am running an ajax update panel in my website. The update panel returns some new controls. I would like to set some JavaScript for the controls after they are returned from the ajax call. Is there any way of doing this? Thanks for any help!
Asked
Active
Viewed 1.1k times
2 Answers
36
tie into the MSAjax Event
function pageLoad(){ }
this will fire every time the update panel refreshes.. you can do your rebinding / new bindings there
...and yes, that's all you need to do, put that on the page and it will fire.
Update:: [looks like i had the function named incorrectly ( i think it would still work tho) ] it's really that simple if you have a script manager on the page..
<script>
///<summary>
/// This will fire on initial page load,
/// and all subsequent partial page updates made
/// by any update panel on the page
///</summary>
function pageLoad(){ alert('page loaded!') }
</script>
http://www.asp.net/ajax/documentation/live/overview/AJAXClientEvents.aspx
Archived:

hanzolo
- 1,151
- 1
- 10
- 18
-
can you post an example. how do I tie something to the MS ajax event? – user516883 Jan 26 '12 at 23:03
-
1Ah, this is MONEY! I haven't worked with webforms in a few years (but have again, just recently). I've remember trying to do this for years. Is this a new feature they added recently or was it just not widely published? – Mike Devenney Jul 16 '15 at 17:13
-
The documentation appears to be gone – Cloud Jan 31 '20 at 04:59
-
1@Cloud, added web archive link. – hanzolo Feb 04 '20 at 19:13
-
@hanzolo - this works only when we add it directly into the aspx. But do not work if we use an external .js file. any idea why it is behaving like that ? – Ananth Jan 21 '21 at 14:36
-
could be an load order issue? Make sure it's being loaded after the "client script manager" loads? and wow, almost 10 years past!!?? – hanzolo Jan 29 '21 at 22:42
-7
You could use a Timer with a function that checks if the controls exists every few hundred ms. Once it detects them, apply your script and end the timer.

Erix
- 7,059
- 2
- 35
- 61