我创建了一个函数,每次单击动态创建的 ImageButton 时都会调用它。但是 precenDefault() 不起作用。该功能正在工作,除了阻止默认值。
jQuery
<script type="text/javascript">
function EmpDelete(event, id) {
event.preventDefault();
$("#bName").text(id);
$('#dialog').dialog({
title: "Delete Employee?",
modal: true,
width: 500,
height: 250,
buttons: {
"Cancel": function () {
$(this).dialog("close");
return false;
},
"Continue": function () {
$(this).dialog("close");
return true;
}
}
});
};
</script>
ASPX.CS
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[iDelete].Controls.Add
(new ImageButton
{
ImageUrl = "Images/database_delete.png",
CommandArgument = e.Row.RowIndex.ToString(),
CommandName = "Delete",
ID = "imgDelete",
CssClass = "imgDelete",
OnClientClick = "return EmpDelete(" + e.Row.Cells[iFNmae].Text + ");"
});
}
}