admin管理员组文章数量:1403187
I want to get a confirm message on clicking delete ImageButton. If the user selects 'Ok' then delete is done, else if 'Cancel' is clicked nothing happens.
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/forDesign/delete.png" OnClientClick="ConfirmDelete()" />
<script type="text/JavaScript"
src=".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");
}
});
}
and in code behind I have:
[WebMethod]
public void Delete()
{
string code = DetailsViewCodeTicket.Rows[2].Cells[1].Text.ToString();
Ticket.TicketCusDelete(code);
DetailsViewCodeTicket.DataBind();
}
but when I clicking the ImageButton I get this error:
How can I do that ?
I want to get a confirm message on clicking delete ImageButton. If the user selects 'Ok' then delete is done, else if 'Cancel' is clicked nothing happens.
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/forDesign/delete.png" OnClientClick="ConfirmDelete()" />
<script type="text/JavaScript"
src="http://ajax.googleapis./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");
}
});
}
and in code behind I have:
[WebMethod]
public void Delete()
{
string code = DetailsViewCodeTicket.Rows[2].Cells[1].Text.ToString();
Ticket.TicketCusDelete(code);
DetailsViewCodeTicket.DataBind();
}
but when I clicking the ImageButton I get this error:
How can I do that ?
Share Improve this question asked Aug 31, 2015 at 16:04 Gholamreza AsadiGholamreza Asadi 1051 gold badge4 silver badges10 bronze badges2 Answers
Reset to default 3You should launch your lightbox on click first.... and then, when the user confirm you trigger your ajax call...
Here an example: http://jsfiddle/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');
}
})
I think you only need to add curly brackets:
if(x){
ajax code ....
}
so this will be the overall code:
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/forDesign/delete.png" OnClientClick="ConfirmDelete()" />
<script type="text/JavaScript" src="http://ajax.googleapis./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>
本文标签: javascriptUse Ajax and Confirm message for deleteStack Overflow
版权声明:本文标题:javascript - Use Ajax and Confirm message for delete - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744404407a2604630.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论