onClientClick executes and then the page postbacks immediately
I have the following code:
functions.js =>
function loadPopup() {
$("#backgroundPopup").css({
"opacity": "0.7"
});
$("#backgroundPopup").fadeIn("slow");
$("#popupContact").fadeIn("slow");
}
//disabling popup with jQuery magic!
function disablePopup() {
$("#backgroundPopup").fadeOut("slow");
$("#popupContact").fadeOut("slow");
}
//centering popup
function centerPopup() {
//request data for centering
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupHeight = $("#popupContact").height();
var popupWidth = $("#popupContact").width();
//centering
$("#popupContact").css({
"position": "absolute",
"top": windowHeight / 2 - popupHeight / 2,
"left": windowWidth / 2 - popupWidth / 2
});
//only need force for IE6
$("#backgroundPopup").css({
"height": windowHeight
});
}
function no() {
return false;
disablePopup();
}
function yea() {
$('#form1').submit(function () {
return true;
})
}
$(function () {
$("#popupContactClose").bind('click', function () {
disablePopup();
});
});
function yeah() {
$(this).bind('click', function (event) {
centerPopup();
loadPopup();
});
}
... and the following markup:
<bod开发者_JAVA技巧y>
<form id="form1" runat="server">
<asp:Button ID="btn1" runat="server" OnClientClick="yeah();" Text="Click me!" />
<div id="popupContact">
<a onclick="xClick()" id="popupContactClose">x</a>
<input type="submit" onclick="yea()" value="Yes" />
<input type="button" onclick="no()" value="No" />
</div>
<div id="backgroundPopup">
</div>
</form>
</body>
</html>
problem is that the OnClientClick event calls yea(), the div shows up and then disappears immediately and the page posts back. This is rather strange. Can you help me with this? Thanks in advance!
I think you need to snuff out the event.
onclick="yea();return false;"
Will probably do it.
精彩评论