0

私が今3秒の遅延でポストバックを行うと考えることができる唯一の方法はこのようなものです。

setInterval("__doPostBack('UpdatePanel1', '' )", 3000); 

私が遭遇した問題は、3秒ごとにポストバックすることです。これを行うためのより良い方法、またはこれの間隔をクリアする方法はありますか?aspupdatepanelコントロールを使用しています。

これが私がやろうとしていることのアイデアをあなたに与えるための私の完全なjavascriptコードです:

    var delayb4scroll = 1000 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
    var marqueespeed = 2 //Specify marquee scroll speed (larger is faster 1-10)
    var pauseAtBottom = 3000 //Pause at the end of the scroll for this many seconds (3000 = 3 seconds)
    var copyspeed = marqueespeed
    var actualheight = ''
    var boolRunOnce = ''

    function pageLoad() {
        initializemarquee();
    }

    function scrollmarquee() {
        if (parseInt(cross_marquee.style.top) - 975 > (actualheight * (-1) + 8)) //if scroller hasn't reached the end of its height
            cross_marquee.style.top = parseInt(cross_marquee.style.top) - copyspeed + "px" //move scroller upwards
        else { //else, scrollbar has reached the bottom, display for 3 seconds then postback
            setInterval("__doPostBack('UpdatePanel1', '' )", 3000);        
        }
    }

    function initializemarquee() {
        cross_marquee = document.getElementById("vmarquee")
        cross_marquee.style.top = 0
        marqueeheight = document.getElementById("marqueecontainer").offsetHeight
        actualheight = cross_marquee.offsetHeight //height of marquee content (much of which is hidden from view)       
        setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
    }
4

1 に答える 1

2
setTimeout(function() { __doPostBack('UpdatePanel1', '' ); }, 3000);

一度だけ実行されます。

または、setIntervalからの戻り値を間隔スレッドへの参照として使用できます。これは、その後クリアできます。

myInterval = setInterval(function() { __doPostBack('UpdatePanel1', '' ); }, 3000);
//later
clearInterval(myInterval);

編集:コメントに従って追加された正しい関数構文。

于 2012-08-01T17:54:44.897 に答える