我有一个asp服务器按钮,当点击它应该执行一些服务器端代码运行一个javascript方法同时按钮看起来像这样:
<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秒然后调用check来调用两种方法来加载和居中弹出窗口
答案 0 :(得分:1)
settimeout调用立即返回。按钮单击将调用发送到服务器,如果服务器调用返回的速度超过10秒,则javascript调用将被取消。整个序列似乎不可靠。
如何从javascript函数本身提交asp.net。
[http://www.codeproject.com/Articles/4368/Post-an-ASP-NET-form-with-JavaScript][1]