c# - Fire up event from Image Button in a User Control inside a Data List -



c# - Fire up event from Image Button in a User Control inside a Data List -

:

this first post here, beg forgive mistkaes :d problem i'm facing following: i'm trying grab event 'imagebutton' within info list experiencing problems.

i need grab button fired action (so need identify it). button within user command contained 'datalist', placed within user control, load page (that has master page also). can see nested order here : page->user-control->datalist->user control->imagebutton

i have web application built using web forms mvp pattern pages (not controls) have presenter manages logic , send info bind web forms, load needed controls.

members.aspx

....... <%@ register src="~/controls/datacontrol.ascx" tagname="databox" tagprefix="dtc" %> ....... <dtc:databox id="databoxcontrol" runat="server" />

members.aspx.cs

protected void page_load(object sender, eventargs e) { _presenter = iocfactory.instance.currentcontainer.resolve<imemberspresenter>(); _presenter.init(this, ispostback); } ...... public void showfriendpanel(ilist<contactinfo> friendlist) { databoxcontrol.friendslist = friendlist.tolist(); }

presenter looks this:

public override void init(imemberview view, bool ispostback) { base.init(view,ispostback);//authentication , basic stuff ilist<contactinfo> friendcontactlist = _useraccountdao.getfriendsofuser(currentuser.id, 0, int.maxvalue); if ((friendcontactlist.count > 0)) { showfriendsbox(friendcontactlist); }

and command databoxcontrol contains info list contains user control

<asp:datalist id="datadl" runat="server" onitemdatabound="datadl_itemdatabound" onitemcommand="datadl_itemcommand" > <itemtemplate> <ci1:contactimage runat="server" id="contactimagecontrol" height="59px" width="59" show="all" /> </itemtemplate> </asp:datalist>

and final user command (contactimage.ascx) contains web command 'imagebutton'

...... <asp:imagebutton id="deletebutton" imageurl="/images/remove_contact_icon.png" runat="server" /> .......

id action assigned in 'contactimage' command image button 'commandname' , that's value need retrieve when button clicked. in fact, contactimage user command doesn't within , rely fired event onitemcommand on info list have 2 problems:

i cannot bind info list before page_load have check info binding taking place when 'ispostback' false; in case, fired event doesn't take place because contactimage fails trying fullfil properties (datalist item empty because list not binding). if info list binding moved page_init (in user control) event fired onitemcommand doesn't receive @ (and list bind info list empty also).

i wonder if pattern i'm using responsible in way because built simple website , works , event reaches itemcommand

simple website (here works no mvp pattern used) event.aspx

<h2> events </h2> <p> events info list </p> <asp:datalist id="datalistwihtevents" repeatdirection="horizontal" repeatcolumns="4" onitemcommand="datalist_itemcommand" runat="server"> <itemtemplate> <tnc:topcontrol id="topcontrolnested" runat="server" number="<%# (container.dataitem) %>" /> </itemtemplate> <separatortemplate>&nbsp;</separatortemplate> </asp:datalist> <br /> <asp:label id="showbuttonfireduptitle" runat="server" text="here goes button fired up: " /> <asp:label id="showbuttonfiredup" runat="server" font-bold="true" />

event.aspx.cs

public partial class events : system.web.ui.page { protected list<int> numbers = new list<int>(); protected void page_init(object sender, eventargs e) { (int = 1; < 5; i++) { numbers.add(i); } datalistwihtevents.datasource = numbers; datalistwihtevents.databind(); } protected void datalist_itemcommand(object source, datalistcommandeventargs e) { if (e.commandsource.gettype() == typeof(button)) { var b = (button) e.commandsource; showbuttonfiredup.text = b.commandname; } }

topnestedcontrol.ascx

<%@ register src="~/controls/bottomnestedcontrol.ascx" tagname="bottomcontrol" tagprefix="bnc" %>

topnestedcontrol.ascx.cs

public partial class topnestedcontrol : system.web.ui.usercontrol { public int number { get; set; } protected void page_load(object sender, eventargs e) { bottomnestedcontrol.number2 = number; } }

bottomnestedcontrol.ascx

<asp:button id="shownumberbutton" runat="server" text="button" commandname="button fired up!" />

bottomnestedcontrol.ascx.cs

public partial class bottomnestedcontrol : system.web.ui.usercontrol { public int number2 { get; set; } protected void page_load(object sender, eventargs e) { shownumberbutton.text = "button " + number2; shownumberbutton.commandname = "#" + number2; } }

in others pages, i'm using delegates handle events, there no 'datalist' used , event catched without problems. glad if help me in anyway untangle mess.

thank in advance,

javier

when many layers exist, page's life cycle plays of import role. instead of going detail on actions should done on cycle (google improve job), i'm going lay out tips , tricks instead.

let page render, utilize ie or chrome or firebugs (for firefox) , press f12. select 1 of buttons in question , see if commandname attribute correctly set. code above, property never set, assumed did on code behind.

if have access button (source of post back), can bind other attributes onto button , utilize information.

if commandname , onitemcommand set up, event still not beingness caught, can attach custom event button , raise it.

on id="datadl" object, remove custom command , set in simple asp:button static command name, run in debug mode , see if triggers datadl_itemcommand. find weird event not firing.

right now, isn't clear post, type of problem having. should limit downwards easier propose solution.

c# asp.net datalist webformsmvp

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -