Koray Durudogan Koray Durudogan - 1 month ago 18
ASP.NET (C#) Question

repeater item command in asp.net

i am working with asp.net and i have a repeater.I want to take a respond from one of the items, which has been displayed by repeater.Here is my code:

<asp:Repeater ID="Repeatercart" runat="server" OnItemCommand ="RepeaterDeleteitemcommand" >
<ItemTemplate>
<table>
<tr>
<td><img id="Image1" src="PerfumeImages/<%#Eval("ProductImage") %>" width="90" /></td>
</tr>
<tr>
<td><%#Eval("ProductName") %> x<%#Eval("Quantity") %></td>
</tr>
<tr>
<td> <%#Eval("ProductGender") %></td>
</tr>
<tr>
<td> <%#Eval("ProductSize") %> ml</td>
</tr>
<tr>
<td><a class="buy-btn"><asp:Button ID="Button1" CommandName="Click" Text="Remove from cart" runat="server" CommandArgument='<%# Eval("ProductId") %>' /></a></td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>


and this is my codebehind:

protected void RepeaterDeleteitemcommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "Click":
Label1.Text = "ok !";
break;
}
}


When i run this code, i get an error like: Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.Thanks for the help

Answer

I solved the problem and wanted to write here, so i can help anyone with the same problem.Adding an "if (!IsPostBack)" under the pageload is solving the problem.Thanks for the all help.

Comments