views:

1331

answers:

6

Is there any kind of event out there that would allow for a preload post back event.

The reason I ask is I have a control that adds sibling controls to it on postback events, however, by the time it has loaded the post back its too late to add the new control to the control collection. Therefore, the controls are never updated correctly.

Thanks!

+1  A: 

Try the Init event.

CodeMonkey1
A: 

Override CreateChildControls (make sure to call base!). In your postback event handler, make sure you are storing somewhere the list of controls that should be created dynamically, so when CreateChildControls gets invoked very early in the lifecycle on the next go-round, it will recreate the controls built on the last postback.

Rex M
A: 

Here is a quick hack. You can always, query the __EventTarget and or the value of the submit button in init and can load dynamically the control.

But doing so, may not be appropriate as your control hierarchy would change and could cause problems.

Ramesh
A: 

As above, dynamic controls have to be added during the page Init event, so that they can be properly handled within the page's Viewstate. You might want to turn the Viewstate off for the page as well, since it can fire errors at you if the controls change.

notnot
A: 

This page explains the event order (and what happens in each one) in a postback, it helped me more than once.

I've just found this link, that can also be of use to you

Juan Manuel
A: 

As has already been stated the proper place to add dynamic controls is in the Init event. Here's an article with more information.

Dynamic Web Controls, Postbacks, and View State

To get a better understanding of the ASP .NET page life cycle see:

ASP.NET Page Life Cycle Overview

Phaedrus