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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

confirm delete

Status
Not open for further replies.

conjurer111

Programmer
Aug 11, 2002
76
IN
Hi,

I got a button (asp button) in my aspx page - cmddelete. I need to popup a message asking for whether the user is sure to delete or not. How do I code this part. Thanks.
 
Code:
cmddelete.attributes.add("onclick","javascript:return confirm('Are you sure you want to permanently delete this record?')")

should do it.
 
Hi,

thanks. one more question, where do I place the code for the deleting part and how do I check for the return values of the confirm dialog box. Can you explain a bit further.
 
well you'd have to have the OnClick event handler (not to be confused with the onClick html attribute) of your delete button call a subroutine that does the deletes.

You don't need to check for the return value. If the user clicks ok to the confirm box, the event procedes, otherwise it just stops and doesn't carry out the click.

make sense?
 
Hi gagz,

If I have a datagrid that has a ButtonColumn . I have on the Datagrid the following event
OnDeleteCommand="dg_Delete"
Sub dg_Delete(Sender As Object, E As DataGridCommandEventArgs)

where do I have to put the confirm delete?
thanks for your help
Al
 
Put in the ItemDataBound Event for the grid.

Private Sub dg_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg.ItemDataBound
If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then
Dim deleteButton As Button = e.Item.Cells(14).Controls(0)
deleteButton.Attributes(&quot;onclick&quot;) = &quot;javascript:return confirm('Are you sure you want to delete this record?')&quot;
End If
End Sub

Hope everyone is having a great day!

Thanks - Jennifer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top