Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
i have put autogeneratDelete button in gridview.i have to apply javascript on this link.Ex: when i click on delete link dialog box open and ask for confirm to delete.
i have try this,but it is not working properly.when i click first time it will not open dialog box ,when i click second time dialog box is open but when i click on cancel ,then also data will be deleted.
 
GridView1.Attributes.Add("onclick", "javascript:confirmDelete('Server ID')");


i have put javascript in .js file.
Posted 15-Jan-13 19:46pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to add this script for every row. For this you need to apply this at RowDataBound event of Gridview.
There are a lots details on it if you search google.
 
You can refer
GridView Delete, with Confirmation[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Please make sure your have wrote your codes to delete any row inside the following if block
 
if(confirm(".....")){
}
 
This will prevent deletion when user press cancel.
 

Also if you can post your code in this forum so it will be more easy for me to debug this.
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{   
if (e.Row.RowType == DataControlRowType.DataRow)   
{      
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)      
{             
((LinkButton)e.Row.Cells[0].Controls[2]).Attributes["onclick"] = "if(!confirm('Are you sure you want to delete this record?'))return  false;";      
}    
} 
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

function confirmDelete(){
                    var userResponse = confirm('Do you want to delete this permanently?');
                    if (userResponse ==true){
                        detachValidationEngine();
                    }
                    return userResponse;
                }
Call it on client click
OnClientClick="return confirmDelete();"
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Hello
 
Use this
 
GridView1.Attributes.Add("OnClientClick", "javascript:return confirm('Are you certain you want to delete this 
product?')");
 

 
also you can used button insted og autoDeleteButton
 

<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
    CommandName="Delete" Text="Delete"
    OnClientClick="return confirm('Are you certain you want to delete this
product?');">
</asp:LinkButton>
 

 
For More Help
http://msdn.microsoft.com/en-us/library/ms972940.aspx[^]
 

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.autogeneratedeletebutton.aspx[^]
 

 
i hope your problem will solve if not please give me your Comment
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100