c# - Need to refresh drop down after we have inserted newly values in database -
i have page using 2 user controls. 1 control reservation control , other channel partners control. on reservation control have drop down has channel partners. when user has new channel partner clicks addnewchannel link , channel partner comes pop , after user inserts new channel partner database. problem whan data inserted database want drop down on reservation refreshed , should contain new channel partner. tried this:
updatepanel upnl = (updatepanel)page.findcontrol("updatepanel1"); if (upnl != null) upnl.update();
my drop down on reservation control in in update panel. didnt work. try appreciated.
assumption: channel partners user control contains popup add new partners. popup has save button (asp.net serverside control) server side click handler commits data database. user control includes additional update panel async postback trigger when user saves new partner form doesn't postback, instead makes async postback
so use events allow user controls talk each other. in case need raise event when new channel partner has been created , have update panel trigged on event.
channel partners user control.
so i'd add new event called newchannelpartnercreated channel partners user control.
public event eventhandler<eventargs> newchannelpartnercreated;
also channel partners user control i'd append save buttons click handler raise event once save has complete successfully.
protected void btnsave_click(object sender, eventargs e) { // code commits new partner database if (errors == false) newchannelpartnercreated(this, null); else // show errors }
reservations user control
amend reservations user control expose public method refresh drop down list , call update method of update panel wraps drop down list
public void refreshchannelpartnerslist() { channelpartnerslistupdatepanel.update(); // databind code might not needed if have have in prerender (not pageload) ddlchannelpartners.datasource = youmethodtogetchannelpartnersfromdatabase(); ddlchannelpartners.databind(); }
user control container page
finally in code behind of page hosts both of users controls; i'd make following change completes picture.
in page load you'd want listen newchannelpartnercreated event raised channel partners user control. event handler needs call refresh method, exposed reservations user control
protected void page_load(object sender, eventargs e) { newchannelpartnerctrl.newchannelpartnercreated += new eventhandler<eventargs>(newchannelpartnerctrl_newchannelpartnercreated); } void newchannelpartnerctrl_newchannelpartnercreated(object sender, eventargs e) { reservationsctrl.updatechannelpartnerslist(); }
Comments
Post a Comment