4

I am using an asp.net update panel to refresh the content on a page when a menu item is selected.

Within the content that is updated are images which have a javascript reflection function which is triggered with the following line of code:

window.onload = function () { addReflections(); }

This runs fine when the page is first loaded but not when a menu item is selected and the update panel is run.

On previous projects using jquery code I have replaced document.ready with function pageLoad but there is no document.ready on this page.

4 Answers 4

4

Like this:

<script>

        // ASP.NET AJAX on update complete   
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_endRequest(function(sender, args) {
           // your code here, eg initToolTips('/Common/images/global/popup3.gif');
        });
Sign up to request clarification or add additional context in comments.

Comments

3

Basically, it's because that event isn't triggered by an update panel refresh.

There are ways to achieve this behaviour though, Ajax.Net has an EndRequestHandler function that you can hook into.

Here's a good example:

http://zeemalik.wordpress.com/2007/11/27/how-to-call-client-side-javascript-function-after-an-updatepanel-asychronous-ajax-request-is-over/

Comments

1

i think u should use

function pageLoad(sender, arg) {
    if (!arg.get_isPartialLoad()) {
        // in first load only
    }
      //every time the update panel refreshed
 }

Regards

Comments

0

Take a look to this event:

window.onload is fired when the entire page is loaded. UpdatePanel uses an AJAX approach, so whenever it's updated and round trip ends, the page remains loaded and only a portion of this has been updated.

In other words, you need to do that "when a request to the server ends".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.