asp.net - asp button on click inside item template not firing -
not able make work.
<asp:templatefield> <itemtemplate> <asp:button id="btnapprove" runat="server" text="approve" onclick ="btnapprove_click" /> </itemtemplate> </asp:templatefield>
code behind:
protected void btnapprove_click(object sender, eventargs e) { response.redirect("viewprofile.aspx"); }
not firing when button clicked. tricks on this?
set enableeventvalidation="false"
right @ top in page directive:
<%@ page enableeventvalidation="false" language="c#"
...
just beware setting value false can expose website security vulnerabilities.as alternative, instead of setting enableeventvalidation="false"
can handle grid views onrowcommand
:
.aspx:
<asp:gridview id="gridview1" runat="server" onrowcommand="gridview1_rowcommand"> <columns> <asp:templatefield> <itemtemplate> <asp:button runat="server" text="approve" commandname="approve" /> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
code behind:
public partial class delete_me : system.web.ui.page { protected void page_load(object sender, eventargs e) { if (!page.ispostback)//this important.gridview1_rowcommand not fire unless add line { var p1 = new person() { name = "person 1" }; var p2 = new person() { name = "person 2" }; var list = new list<person> { p1, p2 }; gridview1.datasource = list; gridview1.databind(); } } protected void gridview1_rowcommand(object sender, gridviewcommandeventargs e) { system.diagnostics.debugger.break(); } } public class person { public string name { get; set; } }
Comments
Post a Comment