同时使用onClientClick时,不会触发asp服务器按钮的onClick事件
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
settimeout 调用立即返回。单击按钮会将调用发送到服务器,如果服务器调用返回速度快于 10 秒,您的 javascript 调用将被取消。整个序列似乎并不可靠。
如何从 javascript 函数本身提交 asp.net?
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.