Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Nov 21, 2011 07:48 PM|LINK
ViewState fails to run correctly and lb.Text is lost after PostBack
Just remember that dynamically created controls will always be lost after postback regardless if using a PlaceHolder or not. You will need to recreate them and add them back to the Placeholder on every postback. I suggest in the Page_OnInit() event or somewhere
similar. Have a look to the following for additional information:
As far as the order of instantion, assignment of properties, and being added to the Placeholder, the MSDN does it in exactly the aforementioned order. Take a look to the following for a code example:
How to: Add PlaceHolder Web Server Controls to a Web Forms Page:
I think the behavior you are seeing is by design and might be where you are doing the assignment. You should really have your code in the OnInit() event. The following post highlights a similar issue that you are having:
Dynamically Loaded Control can not maintain values at PostBack?
"Figure 4 illustrates the sequence of events that transpire, highlighting why the change to the Label's Text property needs to be stored in the view state."
Understanding ASP.NET View State (above excerpt):
If you really think there is a reproducible bug and its not by design, you can report it to Microsoft Connect below:
Hope this helps!