I have a page that contains some dynamically created controls (TextBox and DropDownList). When a postback occurs, the TextBoxes keep their values, but the DropDownLists lose
I always use Page_Load
and never have trouble like this. Maybe something you could look at.
I generally bind data to controls the first time the page loads, and after that let Viewstate handle postbacks etc. Note that they suggest you bind data during Page_Load
...
Check out http://support.microsoft.com/kb/305141
Page Events loadTOCNode(2, 'moreinformation'); During the life cycle of an ASP.NET page, a few standard events that are exposed from the Page object are used frequently. The ASP.NET page framework automatically connects to (or wires up) appropriate delegate instances at run time for these methods. This saves you from having to write the necessary "glue code." The following list presents the delegate instances that are wired up at run time in the order in which they are fired:The following list outlines the events that are non-deterministic:
- Page_Init: During this event, you can initialize values or connect any event handlers that you may have.
- Page_Load: During this event, you can perform a series of actions to either create your ASP.NET page for the first time or respond to client-side events that result from a post. The page and control view state have been restored prior to this event. Use the IsPostBack page property to check whether this is the first time that the page is being processed. If it is the first time, perform data binding. Also, read and update control properties.
- Page_DataBind: The DataBind event is raised when the DataBind method is called at the page level. If you call DataBind on individual controls, it only fires the DataBind event of the controls beneath it.
- Page_PreRender: The PreRender event is fired just before the view state is saved and the controls are rendered. You can use this event to perform any last minute operations on your controls.
- Page_Unload: After a page has finished rendering, the Page_Unload event fires. This event is a good place to perform final cleanup work. This includes items such as the cleanup of open database connections, discarding objects, or closing those files that are open.
- Page_Error: If an unhandled exception occurs during page processing, the Error event fires. The Error event gives you an opportunity to gracefully handle errors.
- Page_AbortTransaction: Transaction events are useful if you want to indicate whether a transaction succeeds or fails. This event is commonly used for shopping cart scenarios in which this event can indicate the success or failure of an order. This event fires when a transaction has been aborted.
- Page_CommitTransaction: This event fires when a transaction has been committed successfully.