">
我希望在单击delete ImageButton时收到确认消息。如果用户选择“确定”,则删除完成,否则,如果单击“取消”,则不会发生任何事情。
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/forDesign/delete.png" OnClientClick="ConfirmDelete()" />
<script type="text/JavaScript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
function ConfirmDelete() {
var x = confirm("Are you sure you want to delete?");
if (x)
$.ajax({
type: "get",
url: "SearchTicket.aspx/Delete",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (response) {
alert(response.status);
},
error: function () {
alert("error");
}
});
}
在后面的代码中,我有:
[WebMethod]
public void Delete()
{
string code = DetailsViewCodeTicket.Rows[2].Cells[1].Text.ToString();
Ticket.TicketCusDelete(code);
DetailsViewCodeTicket.DataBind();
}
但是当我单击ImageButton时,我得到了这个错误:
我该怎么做呢?
发布于 2015-08-31 16:10:55
您应该在单击first...时启动lightbox。然后,当用户确认您触发了ajax调用时...
下面是一个示例:http://jsfiddle.net/leojavier/976oxwmk/
<button>remove</button>
js
$('button').on('click', function(){
var confirmation = confirm("are you sure you want to remove the item?");
if (confirmation) {
// execute ajax
alert('removed');
}
})
发布于 2021-09-07 22:22:31
我认为您只需要添加大括号:
if(x){
ajax code ....
}
因此,这将是整体代码:
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/forDesign/delete.png" OnClientClick="ConfirmDelete()" />
<script type="text/JavaScript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
function ConfirmDelete() {
var x = confirm("Are you sure you want to delete?");
if (x) {
$.ajax({
type: "get",
url: "SearchTicket.aspx/Delete",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (response) {
alert(response.status);
},
error: function () {
alert("error");
}
});
}
}
</script>
https://stackoverflow.com/questions/32315397
复制相似问题