views:

277

answers:

3

please tell me how to maintain state of placeholder. i have a placeholder in which i add many image controls dynamically but when my page get refresh all controls from placeholder gets removed from it. the enableViewstate of placeholder is set to true.. please tell me how to maintain its state..

+2  A: 

I think you need to add the controls in the Page_PreInt() event

rip
not possible..bcoz controls are added on some situations basis
Rajesh Rolen- DotNet Developer
+4  A: 

ViewState registration happens just after the Init events in the Page lifecycle.

If you are adding your dynamic images after Init, then they are not registered as part of ViewState. Your issue will be solved if you add them to your Placeholder control during Page_Init.

womp
please give me solution... how to maintain state when we add controls after page_init.
Rajesh Rolen- DotNet Developer
If you're adding them after Init, then you need to recreate the controls *exactly* the same way on *every* postback. Make sure the image controls have the exact same IDs and everything.
womp
womp... I had to just double-check myself with a quick test app because you have 25K reputation... but you are smoking crack here. Dynamically added controls aren't going to automatically be stored/restored in the ViewState, even when added before or during Pre_Init. Am I mis-understanding something here?
Bryan
Ah... OK, now you are making more sense. ha
Bryan
A: 

You must add dynamic controls on every page load. Controls are not stored in ViewState, only control STATES and data for controls which do not post their data.

Bryan