c# - Invalid postback or callback argument error when button click - Beginner -
i getting following error;
invalid postback or callback argument. event validation enabled using in configuration or <%@ page enableeventvalidation="true" %> in page. security purposes, feature verifies arguments postback or callback events originate server control rendered them. if data valid , expected, use clientscriptmanager.registerforeventvalidation method in order register postback or callback data validation.
i added columm, , added button it, when button fired following c# code gets executed;
asp.net code
<columns> <%-- <asp:boundfield /> definitions here --%> <asp:templatefield> <itemtemplate> <asp:button id="addbutton" runat="server" commandname="addtocart" commandargument="<%# ((gridviewrow) container).rowindex %>" text="add cart" /> </itemtemplate> </asp:templatefield> </columns>
c#
protected void gridview1_rowcommand(object sender,gridviewcommandeventargs e) { if (e.commandname == "addtocart") { int index = convert.toint32(e.commandargument); // retrieve row contains button // rows collection. gridviewrow row = gridview1.rows[index]; } }
how rid of error;
i added <globalization requestencoding="utf-8"/>
error still there. `
update
<asp:gridview runat="server" id="gdv" autogeneratecolumns="true" onsorting="sortrecord" allowsorting="true" datakeynames="hotelname" cellpadding="4" width="746px"> <columns> <%-- <asp:boundfield /> definitions here --%> <asp:templatefield> <itemtemplate> <asp:button id="addbutton" runat="server" commandname="addtocart" commandargument="<%# ((gridviewrow) container).rowindex %>" text="add cart" /> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
what find myself using buttons onclick events instead of gridviewrowcommand. it's easier work part. asp like;
<asp:gridview runat="server" id="gdv" autogeneratecolumns="false" onsorting="sortrecord" allowsorting="true" datakeynames="hotelname" cellpadding="4" width="746px"> <columns> <%-- <asp:boundfield /> definitions here --%> <asp:templatefield> <itemtemplate> <asp:button id="addbutton" runat="server" onclick="addbutton_click" text="add cart" /> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
and c# like;
protected void addbutton_click(object sender, eventargs e) { button btn = (button)sender; gridviewrow row = (gridviewrow)btn.namingcontainer; }
now in code behind can need row, , know you'll getting row want.
hope helps!
Comments
Post a Comment