| | |
Asp.net javascript confirmation box not cancelling
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
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?
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax appliances asp asp.net bc30451 beginner bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn cac checkbox child class click compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownmenu dynamic edit embeddingactivexcontrol feedback findcontrol flash flv form forms gridview homeedition hosting iframe iis javascript jquery list menu mono mssql multistepregistration nameisnotdeclared novell objects order problem ratings relationaldatabases rotatepage save search security serializesmo.table sessionvariables silverlight smartcard sql ssl suse textbox tracking treeview typeof unauthorized validatedate validation vb.net video virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopemnt webdevelopment wizard xml





