Hi, i have been trying to use the javascript confirmation box to delete files from a Gridview, however when ever i click "cancel" on the box it still deletes the file! i really need some help, heres the code i have:
<asp:TemplateField HeaderText="Delete File">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="Delete"
OnClick="DeleteRowButton_Click" OnClientClick="confirm_delete()">
Permanently Delete This File</asp:LinkButton>
</ItemTemplate>
<script type="text/javascript">
function confirm_delete() {
if (confirm("Are you sure you want to delete the highlighted file? ") == true)
return true;
else
return false;
}
</script>
//Delete a selected file from the Server and Gridview
void DeleteRowButton_Click(Object sender, EventArgs e)
{
//Delete file from the server
String fileName = GridView1.SelectedRow.Cells[1].Text;
String filePath = "/UploadedUserFiles/" + User.Identity.Name + "/" + fileName;
System.IO.File.Delete(Server.MapPath(filePath));
lblDeleteResult.Text = fileName + " was successfully deleted!";
// Programmatically delete the selected record from the gridview
GridView1.DeleteRow(GridView1.SelectedIndex);
//Refresh Gridview
GridView1.DataBind();
UploadDetails.Visible = false;
}
basically the DeleteRowButton_Click method runs regardless of whether i click cancel. i would like it to run this method if i click "ok" and do nothing when a click "cancel"
any ideas?
thanks