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:
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:
"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."
atconway
All-Star
16846 Points
2756 Posts
Re: PlaceHolder and ViewState Bug?
Nov 21, 2011 07:48 PM|LINK
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:
http://forums.asp.net/t/1712535.aspx/1
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:
http://msdn.microsoft.com/en-us/library/wwbbhe6w(v=VS.85).aspx
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?
http://geekswithblogs.net/chrishan/archive/2007/03/27/109988.aspx
"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):
http://msdn.microsoft.com/en-us/library/ms972976.aspx
If you really think there is a reproducible bug and its not by design, you can report it to Microsoft Connect below:
http://connect.microsoft.com/
Hope this helps!