This is tricky. I'm guessing (and it's a guess because ASP.NET is not built to handle dynamic controls, and weird things happen), that you're a victim of the ASP.NET Page Lifecycle.
You're creating the controls on Page_Load, which is good, because dynamic controls must be recreated every time. However, by the time they are created, the LoadPostBack stage has already occured.
In order to make this work, you have to recreate your controls prior to the Load stage.
This article ASP.NET Page Life Cycle and Dynamic Controls discusses the topic in-depth.
Basically, you need to overload the LoadViewState method, and recreate your controls there. Then, when LoadPostBack occurs, your controls will be there to receive their values.
tgreer
Made Her Cry
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
The article I linked to explains all of that, complete with sample code and a detailed explanation of the ASP.NET Page Life Cycle.
In short, though, you have to overload the LoadViewState method.
ASP.NET has a "Load" method, ok? And it automatically allows you to overload it by giving you a Page_Load method to code.
You also can see the Initialization method, but Visual Studio warns you not to edit it.
What you don't see are the other methods that are called automatically, which include LoadViewState and LoadPostBackData.
By default, most new users create their controls in Page_Load, because they think that's what happens FIRST. That's not correct. Initialization happens first. Then LoadViewState, then LoadPostBack, then comes the Load.
So you can create your controls during Initialization (which is what Visual Studio does), or you can overload LoadViewState, like so:
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
// your code here
}
tgreer
Made Her Cry
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37