Geeks With Blogs

News Google

Nick Harrison Blog<Nick>.Next()

Through much trial and error and research on the web, I have come up with the guidelines for dealing with dynamically loaded controls.

  • Load the controls in the same order on each post back
  • Add new controls to the Controls array before setting any properties.    Properties set before the control is added to the control array will not be tracked in View State.
  • If an event handled after dynamic controls are added causes diferent controls to be loaded, the newly reloaded controls may need to be explicitely unloaded.    
    • For example, if a page has dynamic controls added based on the month selected, when the user selects a different month, the existing controls will need to be unloaded before the new controls are added.
    • When removing the dynamic controls, start at the end of the list and work your way backward.
  • Rewire any event handlers as soon as the control is reloaded on each post back.

I found the following articles very helpful:   Dispells the myths about when to reload dynamic controls   Clears up some misconceptions that I had about viewstate.    Points out the importance of adding the control to the controls array before setting any properties.  

Posted on Sunday, November 20, 2005 7:19 PM Stylish musings | Back to top

Comments on this post: Guidelines for Dynamically Loaded Controls

# Hi all My name is Anny Obama
Requesting Gravatar...
hi good site thanks
Left by Gabbyy on Feb 08, 2009 10:18 AM

comments powered by Disqus

Copyright © Nick Harrison | Powered by: