c# - Dynamically Removing Controls from Update Panel. -
i have update panel , need remove controls dynamically added can re-add them on asyncpostback. everytime try error stating "collection modified; enumeration operation may not execute". below code using try remove literalcontrols, however; once figure out issue have remove other types. have any
foreach(control xxl in updatepanel1.contenttemplatecontainer.controls.oftype<control>()) { label2.text = label2.text + xxl.gettype(); foreach (literalcontrol lc in updatepanel1.contenttemplatecontainer.controls.oftype<literalcontrol>()) { literalcontrol mylit = (literalcontrol)lc; updatepanel1.contenttemplatecontainer.controls.remove(mylit); updatepanel1.update(); } }
you cannot modify items using foreach
loop, dynamic control or not.
if want modify items, have use normal for
loop.
some general advice using dynamic controls hard , advised avoid @ costs, , use different asp:panel
s change content toggling visibility
. updatepanel
s tend of finicky controls , can place inside them limited. understand "general" advice may hardly applicable particular project, best can.
Comments
Post a Comment