views:

46

answers:

2

Hi all,

im calling page method on mouse over of image slider to show image from database. The problem is i'm getting multiple call backs. So does any one have idea on resolving this issue.

Thanks, Mehul Makwana.

Code which i'm using for page method.

var contextArray = "img";
    pageMethodConcept = {
        callServerSideMethod: function (id) {
            PageMethods.GetItemLargeImage(id, pageMethodConcept.callback, pageMethodConcept.Failcallback, contextArray);

        }, callback: function (result, userContext, imagePreview) {
            //alert(result);
            if (userContext = "img") {
               //replace img source with result
                document.getElementById("displayPreviewImage").src = result;

                return false;
            }
        }, Failcallback: function (result, userContext) {
            alert("failed");
        }
    }

Code for setting timer,

var alertTimer = 0;

            if (alertTimer == 100) {
                alert("time 100");
                alertTimer = setTimeout(pageMethodConcept.callServerSideMethod(this.id), 0);

            }
            else {
                alertTimer = setTimeout(pageMethodConcept.callServerSideMethod(this.id), 100);
                alert("time ");
            }
A: 

Add a timer and send callback only if a certain amount of time is passed from the last callback. You can do it with a counter.

onof
hey Thanks for sugesstion i have something to show u is that what you mean by setting timer just check and see because it is not working with methods but the issue of multiple calls is resolved.I'm editing in my question
mehul9595
A: 

What do you think the timer code is doing exactly?

if (alertTimer == 100) {...

100? What is 100?

setTimeout and clearTimeout

You should be doing something like:

if (alertTimer != 0) {
    /* timeout pending */
    clearTimeout(alertTimer);
    alertTimer = ...
} else {
    /* set timeout */
    alertTimer = ...
}
Ben