I have a commandargument inside an aspx page set to an object variable inside a for loop as below:
<% foreach (PromotionImage p in imageList)
{
%>
<asp:LinkButton runat="server" OnCommand="deleteButton_Click" ID="deleteButton" CommandArgument="<%# p.ImageId.ToString(); %>" ForeColor="Red"
OnClientClick="javascript:return confirm('Are you sure you want to delete this item?');">X</asp:LinkButton>
<%
}
%>
Then in my c# code behind I have the following to try to get this value:
protected void deleteButton_Click(object sender, CommandEventArgs e)
{
int imageId = System.Convert.ToInt32(e.CommandArgument.ToString());
}
However the c# code keeps returning "System.FormatException: Input string was not in a correct format."
When debugging the e.CommandArgument contains the string "<%# p.ImageId.ToString(); %>" rather than the actual ImageId, why is it not evaluating? Though all my other variables evaluate fine?