| | |
Asp.net javascript confirmation box not cancelling
Please support our ASP.NET advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2008
Posts: 41
Reputation:
Solved Threads: 0
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:
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
c# Syntax (Toggle Plain Text)
<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
Last edited by julseypart; Apr 20th, 2009 at 3:18 am.
MODIFY THE BLOW LINE OF CODE:
ASP.NET Syntax (Toggle Plain Text)
OnClientClick="return confirm_delete()"
MARK AS SOLVED if its help you.
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
•
•
Join Date: Apr 2009
Posts: 1
Reputation:
Solved Threads: 0
Please define Javascript onClientClick function as below
OnClientClick="return confirm_delete()"
And that should resolve your issue.
OnClientClick="return confirm_delete()"
And that should resolve your issue.
•
•
•
•
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:
c# Syntax (Toggle Plain Text)
<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
READ FUNCTION BEHAVIOUR.
MARK THE THREAD AS SOLVED. If your problem resolved.
MARK THE THREAD AS SOLVED. If your problem resolved.
MARK AS SOLVED if its help you.
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: ASP Site crashes after sitting idle for 30 minutes.
- Next Thread: how should i do it?
Views: 1419 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 activexcontrol advice ajax alltypeofvideos anathor application asp asp.net bc30451 bottomasp.net browser button c# checkbox click commonfunctions confirmationcodegeneration connection css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist edit editing expose feedback flash form formatdecimal forms formview google grid gridview hosting iframe iis javascript jquery list listbox login microsoft migration mono mouse mssql multistepregistration news numerical object objects panelmasterpagebuttoncontrols parent problem project radio reportemail richtextbox rotatepage save schoolproject search security services session silverlight smartcard software sql sql-server sqlserver2005 suse textbox theft tracking unauthorized update validation vb.net video videos view virtualdirectory vista visualstudio web webapplications webdevelopemnt webprogramming webservice youareanotmemberofthedebuggerusers





