Does anyone know how to create a javascript OnClick event for a ButtonColumn of a DataGrid? I need a cofirm delete box, but I can't think of how to do it.<BR><BR>Thanks,<BR>Joe FioriniYou can't because the button column of a datagrid can only use server-side code at most. What I've had to do is go back to the old ASP way of setting up a table instead of a datagrid. It's a bit of a pain (obviously) because you can't set it up as quickly as a datagrid, but it does work. And that way you can setup delete buttons that are standard <input type="button"> with onclick events. It's still an .aspx page using the new method of ADO, but it simply behaves more like old ASP pages. If anyone else knows of a better method, I'd appreciate hearing it...Actually, I found out that it is possible.<BR><BR>I used the ItemCreated method of the DataGrid, and when the delete item is created, I set the button's onclick event to return my javascript confirmation. Here's the code:<BR><BR> Private Sub MyDataGrid_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgrReviseParts.ItemCreated<BR><BR> Dim cell As System.Web.UI.WebControls.TableCell<BR> Dim c As Web.UI.Control<BR><BR> 'If the DeleteCommand Script has not been created already, then create it<BR> If Not Page.IsClientScriptBlockRegistered("DeleteCommand") Then<BR> Page.RegisterClientScriptBlock("DeleteCommand", "<script>function ConfirmDelete(){ return confirm('Are you sure you want to delete this Part?'); }</script>")<BR> End If<BR><BR> ' Grab the cell in the current row of the DataGrid that contains the DeleteButton<BR> cell = e.Item.Cells(5)<BR><BR> For Each c In cell.Controls<BR> ' I cast c to LinkButton type because the actual type of a <BR> ' linkbutton in a ButtonColumn is DataGridLinkButton,<BR> ' which I assume is derived from the LinkButton class.<BR> ' If you are using an image, or another type of control<BR> ' then before you do the CType(...) line below, try doing:<BR> ' Response.Write c.GetType().ToString() : Response.End<BR> ' to find out what type it is.<BR> CType(c, System.Web.UI.WebControls.LinkButton).Attributes.A dd("onclick", "return ConfirmDelete()")<BR> Next<BR><BR> End Sub<BR> End Class<BR>I'll have to try that out sometime. That's a big problem I had with datagrids that need client side code to accompany them, and it's one of the things I disliked about ASP.NET.Actually, I was able to improve my code a bit. Instead of using a for loop, I can do a check to see if the cell has any controls in it, and if so then set the attributes. Like so:<BR><BR> Private Sub MyDataGrid_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgrReviseParts.ItemCreated<BR><BR> 'If the DeleteCommand Script has not been created already, then create it<BR> If Not Page.IsClientScriptBlockRegistered("DeleteCommand") Then<BR> Page.RegisterClientScriptBlock("DeleteCommand", "<script>function ConfirmDelete(){ return confirm('Are you sure you want to delete this Part?'); }</script>")<BR> End If<BR><BR> ' Grab the cell in the current row of the DataGrid that contains the DeleteButton<BR><BR> If e.Item.Cells(5).Controls.Count > 0 Then<BR> CType(e.Item.Cells(5).Controls(0), Web.UI.WebControls.LinkButton).Attributes.Add("onclick", "return ConfirmDelete()")<BR> End If<BR><BR> End Sub<BR>