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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With