I'm trying to use a gridviewcommand to delete an entry in the gridview (as well as from the datacontext), but I want to ask the user to confirm or not first. I have a seperate linkbutton to execute the delete code using the ID of the item in the row that the user clicked the delete button in.
When the user clicks delete, my codebehind sets the CommandArgument property of the other linkbutton to basically be the same command argument that it passed. But when the user goes to confirm the deletion, all of a sudden the commandargument of the confirmation link is an empty string? Is the property being flushed after the first postback?
Here is my code:
ASPX
<asp:LinkButton ID="lbDelete" runat="server" Text="Delete" CommandName="delete" CommandArgument='<%# Eval("TheId") %>' /> //Delete LinkButton
<asp:LinkButton ID="confirmDelete" runat="server" OnClick="confirmDelete_Click" Text="Delete" /> //Confirmation Button
C#
rowCommandFunction(object sender, GridViewCommandEventArgs e)
{
// blah blah blah
...
confirmDelete.CommandArgument = e.CommandArgument.ToString();
...// I've put a breakpoint here, and it is setting the value properly...
}
confirmDelete_Click(object sender, EventArgs e)
{
//...but when this line tries to run, comfirmDelete.CommandArgument is set to an empty string?
int selectedId = int.Parse(confirmDelete.CommandArgument);
...
}