c# - Click event not firing on dynamically added LinkButton -


i have linkbutton created dynamically in load , added control resides on master page. here original code used create linkbutton:

lockunlock = new linkbutton() { id = "lockunlock", visible = false }; lockunlock.click += lockunlock_click; 

now, when first dug problem thought might related asp.net life cycle moved code override oninit, didn't fix it.

i moved on setting id because that's not being done. added line:

lockunlock.id = "lockunlock"; 

and tried in both oninit , load - no luck.

then thought, because i'm adding custom control part of contentplaceholder may need make id static work, added this:

lockunlock.clientidmode = clientidmode.static; 

i have tried in load, no luck, , if it's not working in load it's not going change in oninit - first move , hail mary in lot of ways.

alright, i'm @ point feel it's related fact resourcecenter custom control added contentplaceholder , event, though it's technically hooked up, can't fired because of context of class. i'm not sure go here.

do need add shared class click? need hookup click in custom control , delegate there somehow?

i prefer not use either of solutions, hey, have do! forward everybody's input on this.

edit

the code adds control resourcecenter looks this:

this.resourcecenter.addadminlink(lockunlock.visible ? lockunlock : null); 

and code inside resourcecenter control adds list looks this:

if (link == null) { return; }  var wrapper = new htmlgenericcontrol("li"); wrapper.controls.add(link);  this.adminlinklist.controls.add(wrapper); 

where link passed method aforementioned line.

it have in init. also, try adding control control's collection, before adding event, in:

lockunlock = new linkbutton() { id = "lockunlock", visible = false }; panel.controls.add(lockunlock); lockunlock.click += lockunlock_click; 

Comments