2012-01-29 35 views
0

我有一個asp服務器按鈕,點擊時應預先形成一些服務器端代碼運行javascript方法在同一時間按鈕看起來像這樣:onClick事件的asp服務器按鈕沒有被觸發時,同時使用onClientClick

<asp:Button ID="Button3" runat="server" onclick="Button3_Click" OnClientClick="timing()" Text="Check Spam" />

點擊首次一切工作正常兩種方法執行,但如果按鈕被再次點擊只有我搜索,找到了一些解決方案,但他們沒有爲我工作的JavaScript方法執行 ,任何幫助應用程序時將不勝感激 預先感謝很多

使用的JavaScript方法是

var popupStatus = 0; 
function loadPopup() { 
    //loads popup only if it is disabled 
    if (popupStatus == 0) { 
     var test = document.getElementById('ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder2_hidden1').value + "<div>success <input id=\"Button1\" type=\"button\" value=\"button\" onclick=\"disablePopup()\" /> </div>"; 
     $("#popupContact").html(test); 
     $("#backgroundPopup").css({ 
      "opacity": "0.7" 
     }); 
     $("#backgroundPopup").fadeIn("slow"); 
     $("#popupContact").fadeIn("slow"); 
     popupStatus = 1; 
    } 
} 

function disablePopup() { 
    //disables popup only if it is enabled 
    if (popupStatus == 1) { 
     $("#backgroundPopup").fadeOut("slow"); 
     $("#popupContact").fadeOut("slow"); 
     popupStatus = 0;  
    } 
} 

function centerPopup() { 
    //request data for centering 
    // var windowWidth = document.documentElement.clientWidth; 
    var windowHeight = document.documentElement.clientHeight; 
    var windowWidth = document.documentElement.clientWidth; 
    var popupHeight = $("#popupContact").height(); 
    var popupWidth = $("#popupContact").width(); 
    //centering 
    $("#popupContact").css({ 
     "position": "absolute", 
     "top": windowHeight.top - popupHeight/2, 
     "left": windowWidth/2 - popupWidth/2 
    }); 
    //only need force for IE6 

    $("#backgroundPopup").css({ 
     "height": windowHeight 
    }); 

} 

function check() { 
    centerPopup(); 
    loadPopup(); 
} 

function timing() { 
    setTimeout('check()', 10000); 
} 

函數定時等待10秒,然後調用檢查至極調用兩種方法來立即加載和居中的彈出

+0

我想你應該張貼在計時碼()函數 – chandmk 2012-01-29 12:44:41

+0

我編輯的問題,並添加使用的所有的JavaScript函數 – 2012-01-30 13:15:29

回答

1

setTimeout調用返回。然後點擊按鈕將呼叫發送到服務器,如果服務器調用返回的速度超過10秒,您的JavaScript呼叫將被取消。整個序列似乎並不可靠。

如何提交asp.net形式的javascript函數本身。

[http://www.codeproject.com/Articles/4368/Post-an-ASP-NET-form-with-JavaScript][1] 
相關問題