2 Hi,
Please write this code on source code:
<asp:Button ID="Delete" runat="server" onclick="Delete_Click"
OnClientClick="javascript: return confirm('Are you sure want to Delete?')"
Text="Delete" />
1 Hi,
generate OnRowDataBound event for Gridview and write the following code
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string item = e.Row.Cells[0].Text;
foreach (Button button in e.Row.Cells[2].Controls.OfType<Button>())
{
if (button.CommandName == "Delete")
{
button.Attributes["onclick"] = "if(!confirm('Do you want to delete " + item + "?')){ return false; };";
}
}
}
}
for more information please refer the following URL
http://www.aspsnippets.com/Articles/Delete-ASPNet-GridView-Row-with-JavaScript-Confirmation-Box-using-CommandField-and-OnRowDeleting-event.aspx
If you find anything helpful please accept my answer
1 Use below function-
function deleteArticle(hdnPostId, divContainer) {
if (confirm("Are you sure?"))
{
$.ajax({
type: "POST",
url: "TestPage.aspx/DeleteArticle",
data: "{PostId: '" + hdnPostId + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$('#' + divContainer).hide();
},
failure: function (errMsg) {
alert(errMsg);
}
});
}
return false;
}
in code behind call like this-
hypDelete.Attributes.Add("onclick","javascript:deleteArticle('"+hdnPostId.Value+"','"+divContainer.ClientID+"');return false;");
1 Hi,
define one button like this
<asp:LinkButton ID="lbDelete" runat="server" OnClick="lbDelete_Click" OnClientClick="return fnConfirm();"> Delete</asp:LinkButton>
write javascript function for button like
<script type="text/javascript">
function fnConfirm() {
if (confirm("The item will be deleted. Are you sure want to continue?") == true)
return true;
else
return false;
}
in lbDelete_Click event write the logic for deletion of item
for more information please refer the following link
http://www.dotnetpickles.com/2013/03/how-to-show-confirm-message-while.html
If you find anything helpful please accept my answer
1 Hi Murugavel,
Please find below code:
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display a confirm box.</p>
<asp:Button ID="btnDelete" onclientclick="return myFunction()" OnClick="CallServerMethod()"
<p id="demo"></p>
<script>
function myFunction() {
var result = confirm("Press a button!");
if (result == true) {
return true;
} else {
return false;
}
}
</script>
</body>
</html>
0 Hello All,
Thanks a lot for ur Replies..
Im sorry , in form I used <asp:commandfield> for delete .
in that there is no property called onclientclick and OnClick.
so, how to display confirm msg before deleting item.?
im using <asp:commandfield> for delete..
Thanks in Advance