i have asp.net listbox populated in page_load event if not postback. whenever users selects item asp.net listbox, need load usercontrols based upon how many items selected listbox. have been able load multiple controls; however, problem newly added controls disapper on postback.
here sample code
if (!this.ispostback) { bindlistbox(); } private void bindlistbox() { lstagenylist .datasource = getagenylist(); lstagenylist.datatextfield = "id"; lstagenylist.datavaluefield = "name"; lstagenylist.databind(); } protected void lstagenylist_onselectedindexchanged(object sender, eventargs e) { foreach(item in lstagenylist.items) { if(item.selected) { addcontrols(item.text, item.value); } } } private void addcontrols(string itemname, string itemvalue) { var control = this.loadcontrol("~/controls/a.ascx"); control.id= itemname.trim() + itemvalue + "controls_"; this.agenylistplaceholder.controls.add(control); }
so questons guys, best options implementing logic in asp.net web form.
it has placeholder , dynamically added controls.
answer same question here: http://forums.asp.net/t/1623719.aspx
basically, everyting in placeholder lost upon post , have re-add during preinit event hidden fields, request.form, or viewstate.