asp.net - Event from dynamic ItemTemplate not caught -
asp.net - Event from dynamic ItemTemplate not caught -
i implemented new dynamic itemtemplate :
private sealed class customitemtemplate : itemplate { public customitemtemplate() {} void itemplate.instantiatein(control container) { table itemtable = new table(); itemtable.cssclass = "tablewidth"; tablerow btnrow = new tablerow(); itemtable.rows.add(btnrow); tablecell btncell = new tablecell(); btncell.cssclass = "bgcolorbluelight"; btncell.columnspan = 2; btnrow.cells.add(btncell); imagebutton imgbtnfvprincipalinsertmode = new imagebutton(); imgbtnfvprincipalinsertmode.causesvalidation = false; imgbtnfvprincipalinsertmode.imageurl = "~/images/icon_insert_16.gif"; imgbtnfvprincipalinsertmode.commandname = "new"; imagebutton imgbtnfvprincipalupdatemode = new imagebutton(); imgbtnfvprincipalupdatemode.causesvalidation = false; imgbtnfvprincipalupdatemode.imageurl = "~/images/icon_edit_16.gif"; imgbtnfvprincipalupdatemode.commandname = "edit"; btncell.controls.add(imgbtnfvprincipalinsertmode); btncell.controls.add(imgbtnfvprincipalupdatemode); container.controls.add(itemtable); } }
it contains 2 buttons, first 1 opening insert mode , sec 1 opening update mode. show no problem.
my goal utilize in formview :
protected void page_load(object sender, eventargs e) { formview1.itemtemplate = new customitemtemplate(); }
and i'd grab commands 2 buttons :
protected void formview1_itemcommand(object sender, formviewcommandeventargs e) { system.diagnostics.debug.writeline("item commandname : " + e.commandname); }
unfortunately, formview1_itemcommand won't display when click on buttons
yet, if declare itemtemplate classicaly :
<%@ command language="c#" autoeventwireup="true" codefile="prospectscustomformview.ascx.cs" inherits="controls_prospectscustomformview" %> <asp:formview id="formview1" runat="server" onitemcommand="formview1_itemcommand"> <itemtemplate> <asp:table id="itemtable" runat="server" cssclass="tablewidth"> <asp:tablerow> <asp:tablecell cssclass="bgcolorbluelight" columnspan="2"> <asp:imagebutton id="imgbtnfvprincipalinsertmode" runat="server" commandname="new" causesvalidation="false" imageurl="~/images/icon_insert_16.gif" tooltip="new"/> <asp:imagebutton id="imgbtnfvprincipalupdatemode" runat="server" commandname="edit" causesvalidation="false" imageurl="~/images/icon_edit_16.gif" tooltip="edit" /> </asp:tablecell> </asp:tablerow> </asp:table> </itemtemplate> </asp:formview>
then works...
which solution suggest ?
edit
forgot mention formview wrapped within user command :
public partial class controls_customformview : usercontrol { protected void page_load(object sender, eventargs e) { fv.itemtemplate = new customitemtemplate(); } private sealed class customitemtemplate : itemplate {...} }
this little outside experience, note don't show buttons raising events within template. don't appear handling events raised button commands.
there's nil see create buttons cause template object live in raise itemcommand
event.
like said, bit outside experience, maybe that's supposed auto-wire itself. i'd seek handling buttons' command
event , having them raise itemcommand
of template.
eta: having done reading, think luizgrs right , shouldn't need special event handling.
i'm wondering if problem not adding of controls container.controls
until end. doing way, you're relying on add
method of container.controls
go through command hierarchy of table
, hook command events bubbleevent
.
just experiment, seek moving line:
container.controls.add(itemtable);
... right top, this:
table itemtable = new table(); itemtable.cssclass = "tablewidth"; container.controls.add(itemtable);
the difference command additions controls within container.controls
.
eta: also! need assign id buttons!
imagebutton imgbtnfvprincipalinsertmode = new imagebutton(); imgbtnfvprincipalinsertmode.id = "imgbtnfvprincipalinsertmode"; imgbtnfvprincipalinsertmode.causesvalidation = false; imgbtnfvprincipalinsertmode.imageurl = "~/images/icon_insert_16.gif"; imgbtnfvprincipalinsertmode.commandname = "new";
asp.net formview itemtemplate itemcommand
Comments
Post a Comment