Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I get a Confirm box? 1

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
I have my datagrid, all happy and functional... updates and everything. However, I have a Delete button that does nothing. Why? Because I don't want them to use it unless I can warn them.

So, I would like to have some sort of Confirm box, like, 'do you really want to do this?'. It looks like I'll have to do that Javascript side, BUT, can I then call my .Net code that deletes the item? Or do I need do do something else.
 
Hey qwert (or whoever you are)
;)

You can do it from code behind. Just add this sub

Private Sub YOURDATAGRID_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles YOURDATAGRID.ItemDataBound

If Not (e.Item.FindControl("Delete") Is Nothing) Then
Dim Button As New ImageButton()
Button = e.Item.FindControl("Delete")
Button.Attributes.Add("onClick", "return confirm('Are you sure you wish to delete this item?');")
End If
End Sub


I use an image button for my delete, but if you have a link button or something else, just switch the
Dim Button as New statement to whatever you use.

Hey, btw, I cleared outmy cookies, and when I re-logged in it gave me the right username, so maybe thats all there is to fix our little name-swap. Still seems weird that it happened though.

D'Arcy
 
Yup, thanks.
And Dave said if it happens again, just call him and let him know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top