View Single Post
  #3 (permalink)  
Old February 20th, 2004, 04:35 PM
planoie's Avatar
planoie planoie is offline
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This is what happens you create controls and add them to the page programmatically:

Stage 1: Initial page hit (no postback)
1) ASPX markup is parsed (with no dynamic controls)
2) Page_load(): you add controls to the page's controls collection.
3) Page does whatever else it needs (i.e. fires events, etc)
4) States and values of all page controls (INCLUDING dynamic controls) are saved to the page's viewstate
5) All controls are rendered

Stage 2: form postback
1) ASPX markup is parsed (with no dynamic controls)
2) Control values and states are restored from viewstate. Controls who's values have changed assume the new (posted) value.
3) Page_load(): you add controls to the page's controls collection.
3a) When each control is loaded and added to the page, the framework attempts to match it up with information in viewstate to restore its condition.
4) Page does whatever else it needs (i.e. fires events, etc)
4) States and values of all page controls (INCLUDING dynamic controls) are saved to the page's viewstate
5) All controls are rendered

As long as you use the same control ID when you create the controls, they should restore correctly. If you need to preset a control that is created dynamically, you should only preset it when the page is in its first instance (i.e., If Not IsPostback ...).

Peter
------------------------------------------------------
Work smarter, not harder.