Hello,
I've got a repeater control that lists usernames and has a few buttons to interact with the user. The one I'm concerned about is a Delete button that passes an ID as the command argument:
Yes, it's eventually going to be an ImageButton with a big red X, but right now it just says it is.
The code behind on the repeater.ItemCommand event looks for the button id = "DeleteRecipient", gets the ID from the CommandArgument and deletes the record from the DB.
The code works fine. If you click on the "Big Red X" button that record is deleted and the page refreshes with the message "Recipient Deleted" and the record is gone from the list.
The problem comes when you refresh the page. It asks if you want to resubmit the form, you know someone will do it so I have to test. In that case it deletes the NEXT record on the list. It should be passing the ID of that record in and the delete should fail, or at least do nothing.
Why is it deleting the next record. If you keep refreshing and resubmitting the form it will keep deleting the next record until all are gone.
Please help
Thanks
Travis Hawkins
jobs.bestcodingpractices.com
I've got a repeater control that lists usernames and has a few buttons to interact with the user. The one I'm concerned about is a Delete button that passes an ID as the command argument:
Code:
<asp:Button ID="DeleteRecipient" CommandArgument='<%#Container.DataItem.ID %>' Text="Big Red X" runat="server" OnClientClick="confirmDelete()"/>
Yes, it's eventually going to be an ImageButton with a big red X, but right now it just says it is.
The code behind on the repeater.ItemCommand event looks for the button id = "DeleteRecipient", gets the ID from the CommandArgument and deletes the record from the DB.
Code:
ElseIf Btn.ID = "DeleteRecipient" Then
Dim Recip As String = e.CommandArgument.ToString()
If Not Recip = "" Then
Dim RecipId As Integer
If IsNumeric(Recip) Then
RecipId = CInt(Recip)
' Delete code is handled elsewhere, and is working fine
Dim Opt As New tdb_OptInCell(RecipId)
If Opt.DeleteRecipient(RecipId) Then
ActMessage.Text = "Recipient Deleted"
Else
ActMessage.Text = "Unable to Delete Recipient"
End If
End If
End If
End If
The code works fine. If you click on the "Big Red X" button that record is deleted and the page refreshes with the message "Recipient Deleted" and the record is gone from the list.
The problem comes when you refresh the page. It asks if you want to resubmit the form, you know someone will do it so I have to test. In that case it deletes the NEXT record on the list. It should be passing the ID of that record in and the delete should fail, or at least do nothing.
Why is it deleting the next record. If you keep refreshing and resubmitting the form it will keep deleting the next record until all are gone.
Please help
Thanks
Travis Hawkins
jobs.bestcodingpractices.com