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..
not possible..bcoz controls are added on some situations basis
Rajesh Rolen- DotNet Developer
2010-01-19 07:11:33
+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
2010-01-19 06:58:38
please give me solution... how to maintain state when we add controls after page_init.
Rajesh Rolen- DotNet Developer
2010-01-19 07:12:29
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
2010-01-19 07:20:54
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
2010-01-19 07:23:47
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
2010-01-19 07:16:12