同时使用onClientClick时,不会触发asp服务器按钮的onClick事件

发布于 2024-12-29 08:56:06 字数 1989 浏览 0 评论 0原文

我有一个 asp 服务器按钮,单击该按钮时应执行一些服务器端代码,同时运行 javascript 方法,该按钮如下所示:

第一次单击应用程序时,一切正常,两种方法都会执行,但如果再次单击按钮,则仅执行 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 秒,然后调用 check 调用两个方法来加载和居中弹出窗口

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彡翼 2025-01-05 08:56:06

settimeout 调用立即返回。单击按钮会将调用发送到服务器,如果服务器调用返回速度快于 10 秒,您的 javascript 调用将被取消。整个序列似乎并不可靠。

如何从 javascript 函数本身提交 asp.net?

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

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]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文