Javascript confirmation message in datagrid

P

Peter Afonin

Hello,

I need to add a confirmation message to the Delete button in the datagrid.

I was always using this code to do this:

Private Sub dgRoles_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgRoles.ItemCreated
'------------------------------------------------------------------------------------------------
' Display delete confirmation message
'------------------------------------------------------------------------------------------------
Try

Dim BtnDel As LinkButton

Select Case e.Item.ItemType

Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem

BtnDel = CType(e.Item.FindControl("lbDelete"), LinkButton)
BtnDel.Attributes.Add("onclick", "return confirm('Are you sure you want to
remove this role?');")

End Select

Catch ex As Exception

Me.lblError.Text = "Error No.: " & Err.Number.ToString & " - " & ex.ToString

End Try

End Sub

I have used this code for years, so I know it works. But in my latest
application I'm having some problems with it.

First, the message is not always displayed, and I cannot find any pattern
when it's displayed and when it's not.

Second, even if the message is displayed correctly, no matter what button I
click - OK or Cancel - the command is executed, and the deletion occurs.

Do you have any idea where the problem might be?

I would appreciate any suggestions.

Thank you,

Peter
 
N

nahid

Hello,

I need to add a confirmation message to the Delete button in the datagrid.

I was always using this code to do this:

Private Sub dgRoles_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgRoles.ItemCreated
'--------------------------------------------------------------------------­----------------------
' Display delete confirmation message
'--------------------------------------------------------------------------­----------------------
Try

Dim BtnDel As LinkButton

Select Case e.Item.ItemType

Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem

BtnDel = CType(e.Item.FindControl("lbDelete"), LinkButton)
BtnDel.Attributes.Add("onclick", "return confirm('Are you sure you want to
remove this role?');")

End Select

Catch ex As Exception

Me.lblError.Text = "Error No.: " & Err.Number.ToString & " - " & ex.ToString

End Try

End Sub

I have used this code for years, so I know it works. But in my latest
application I'm having some problems with it.

First, the message is not always displayed, and I cannot find any pattern
when it's displayed and when it's not.

Second, even if the message is displayed correctly, no matter what button I
click - OK or Cancel - the command is executed, and the deletion occurs.

Do you have any idea where the problem might be?

I would appreciate any suggestions.

Thank you,

Peter

hi,
see this hope help
http://nahidulkibria.blogspot.com/2007/05/javascript-confirm-using-at.html

thanks
nahid
 
G

Guest

Thank you, Nahid.

But this is almost exactly what I use. Only you use gridview with ASP.NET
2.0, and I'm using Datagrid with 1.1.
 
G

Guest

I understand now why the message box wasn't always there, so this has been
taken care of, but I still cannot understand why the delete command is always
executed, no matter what button I press.

Thanks,

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top