c# - Pass data between 2 dynamically loaded User control -


i have scenario dynamically load 2 user controls in webform, , need them interact together. here's code :

default.aspx.cs controla ca = (controla)loadcontrol("~/controla.ascx"); controlb cb = (controlb)loadcontrol("~/controlb.ascx"); page.controls.add(ca); page.controls.add(cb); 

now thing is, controlb needs pass data controla. data not event (well part of). when user click on link controlb, data db, , need pass controla id of first data fetch request. , of course, when user click on link in controlb, page postback.

i looked @ events & delegates, can't make work. right way go ?

if have clue, appreciated !

a quick , dirty method comes mind declare id of first data fetch public property of controlb, , set value on link postback's handler on controlb eg. on controlb's event handler :

public void link_click(object sender, eventargs e) {  this.firstfetchedid = getvaluefromdb(); } 

then on controla's prerender :

protected override void onprerender(eventargs e) { controlb cb = this.page.findcontrol("controlbid") controlb; // either id or loop trough controls find type var youridishere = cb.firstfetchedid; base.onprerender(e); } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -