asp.net - OnClick Event for Button in GridView is not working -
here datagridview
<asp:gridview id="gvpredstave" runat="server" cssclass="gridview" alternatingrowstyle-cssclass="even" autogeneratecolumns="true"> <columns> <asp:templatefield> <itemtemplate> <asp:button id="btnrezervisi" runat="server" text="rezervisi" onclick="button1_click" /> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
this code click on button in gridview
protected void button1_click(object sender, eventargs e) { response.redirect("aktivnerezervacije.aspx?korisnicko_ime=" + korisnicko_ime); conn.close(); }
when click on button got error in browser:
invalid postback or callback argument. event validation enabled using <pages enableeventvalidation="true"/> 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.
does know reason why happening. tried enableeventvalidation="false" doesn't work.
i recreated error using gridview , binding it. answer lies on page_load
event. if have this:
protected void page_load(object sender, eventargs e) { bindgridview(); //code bind gridview }
you exception. change to:
protected void page_load(object sender, eventargs e) { if (!ispostback) { bindgridview(); } }
and should not error anymore.
Comments
Post a Comment