Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 408
Koray Durudogan Avatar asked Nov 10 '22 07:11

Koray Durudogan


1 Answers

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.

like image 177
Koray Durudogan Avatar answered Nov 14 '22 23:11

Koray Durudogan