简体   繁体   中英

onClick event of asp server button is not fired when using onClientClick at the same time

i have an asp server button that when clicked should preform some server side code run a javascript method at the same time the button looks like this:

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

when clicking the application for the first time everything works fine both methods execute but if the button is clicked again only the javascript method executes i searched and found some solutions but none of them worked for me, any help will be appreciated thanks a lot in advance

the javascript methods used are

    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);
}

function timing waits 10 seconds then calls check wich calls a two methods to load and center a popup

settimeout call returns immediately. And the button click sends the call to server, if the server call returns faster than 10 secs, your javascript call gets cancelled. The whole sequence doesn't seem to be reliable.

How about submitting asp.net form the javascript function itself.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM