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>