【发布时间】:2011-10-17 15:30:03
【问题描述】:
看起来 Internet Explorer 恶魔又来了,我似乎无法弄清楚这一点:
我有一个 ImageButton 使用 OnCommand 从我的数据库中删除特定条目。然而,我已经实现了它,以便用户首先确认他们想要删除特定项目。
这是我的 ImageButton 的代码
<asp:ImageButton runat="server" ID="imgDelete" ImageUrl="~/Controls/TaskDetails/Images/delete.png" OnCommand="Tag_DeleteCommand" Visible='<%# CanDelete %>' OnClientClick="javascript:confirmDialog(this, 'Remove Tag','Are you sure you want to remove this tag?', 1); return false;"
CommandArgument='<%# Eval("TagID") %>' />
这是我的 ConfirmDialog 函数
function confirmDialog(sender, title, message, type) {
//type entities
//1 = warning
//2 = error
//3 = success
//4 = Information
var sender = $(sender);
$("#message_dialog_inner_text").html(message);
$("#message_dialog_message_container").dialog({
modal: true,
title: title,
zIndex: 10003,
dialogClass: (type > 0) ? "message_dialog_type_" + type : "",
position: 'center',
buttons: {
"OK": function () {
//the yes option was selected, we now disable the onclientclick event, and fire the click event.
$(this).dialog("close");
if (sender.hasAttr("href")) {
window.location = sender.attr('href');
} else {
sender.removeAttr("onclick");
sender.trigger("click");
}
},
"Cancel": function () { $(this).dialog("close"); }
}
});
return false;
}
这在 Chrome、FF、Safari 中运行良好,但 IE 只是忽略它并进行回发。我什至将我的 OnClientClick 更改为“return false;”它似乎对回发按钮没有影响。我也将其从 ImageButton 更改为仅 Button,但无济于事。我假设它与 OnCommand 事件有关,但是我不知所措!我已经实现了这个非常庞大的应用程序,所以我想管理更改的范围。如果有人有一些意见,将不胜感激!
编辑
好的,我也强调一下,我不希望它回发,即使我只有 OnClientClick="return false;"命令按钮仍在回发(不是您所期望的)。
这是来自我的 ImageButton 控件的渲染标记
<input type="image" name="ctl00$body$pnlContentRight$pnlCurrentTaskDetails$repTags$ctl00$tagItem$imgDelete" id="ctl00_body_pnlContentRight_pnlCurrentTaskDetails_repTags_ctl00_tagItem_imgDelete" src="Controls/TaskDetails/Images/delete.png" onclick="javascript:confirmDialog(this, 'Remove Tag','Are you sure you want to remove this tag?', 1); return false;" style="border-width:0px;">
【问题讨论】:
-
你试过把开头改成 OnClientClick="return confirmDialog(... ?
-
你能发布呈现的 HTML 吗?我怀疑你是对的,OnCommand 可能是罪魁祸首。查看发送到浏览器的实际 HTML/JS 可能有助于诊断。
-
Doozer: 我试过“return confirmDialog();”但它并没有改变 IE 如何不想阻止回发的发生。超级奇怪,这似乎与 IE 有关,因为 chrome 处理我所期望的一切。 MikeManne:我已经更新了我的问题以包含渲染的标记。
标签: javascript asp.net internet-explorer postback imagebutton