Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello sir.
i have a gridview in one page. below gridview i have two buttons named Add to Cart and Remove From Cart. i give the codeing for Add to Cart button like below in gridview RowCommand event
XML
<asp:GridView ID="GV" runat="server" AutoGenerateColumns ="false"
                        onselectedindexchanged="GV_SelectedIndexChanged" onrowcommand="GV_RowCommand"
                        onrowdatabound="GV_RowDataBound" >
                        <Columns >
                            <asp:BoundField HeaderText ="ID" DataField ="eid" />
                            <asp:BoundField HeaderText ="ENAME" DataField ="ename" />
                            <asp:BoundField HeaderText ="IMAGE PATH" DataField ="image" />
                            <asp:TemplateField HeaderText ="IMAGE">
                                <ItemTemplate>

                                    <asp:Image ID="Img" runat="server" ImageUrl='<%#Eval("image")%>' Width="50" Height="50"/> <br />
                                    <asp:Button ID="BtnAdd" runat="server" Text="Add To Cart"  CommandName="add" CommandArgument ='<%#Eval("eid") %>'/>
                                    <asp:Button ID="btnremove" runat="server" Text="Remove From Cart"   CommandName="remove"  />

                                </ItemTemplate>
                            </asp:TemplateField>

                        </Columns>
                    </asp:GridView>



C#
protected void GV_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "add")
        {

            Response.Redirect("~/AddToCart.aspx");
        }
    }



when ever i click this Add To Cart button below errro is comign. any body plz help me.

XML
System.ArgumentException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> 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.
Posted

1 solution

 
Share this answer
 
Comments
sathish.jampala 1-Jan-11 10:55am    
thank you sir. thanks for ur quick reply. but it is not working.
i make EnableEventValidation="false" and
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{


ClientScript.RegisterForEventValidation("BtnAdd ");

base.Render(writer);

}
if i tri this page is not postback.

give me another solution please.

thanking you.
[no name] 1-Jan-11 11:11am    
You NEVER want to set EnableEventValidation="false", this bypasses security aspects of ASP.NET forms and is NOT a good idea.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900