Because you add the control dynamically to the control collection, it does not get added to that same collection on postback. If you want to have it there, then you need to add it each time, regardless of whether it is postback or not. And, depending on what you are going to do with the control, you may want to add it in the init event of the page so it can get processed properly.
HTH, Matt -----Original Message----- From: Bailey, Mark To: [EMAIL PROTECTED] Sent: 5/23/02 8:54 AM Subject: [DOTNET] Dynamically added controls not visible on PostBack Hi: I have a placeholder on my webform, to which I add WebControls dynamically. The controls are added and appear fine on the form. The problem I notice is that when I post the form, I can't access these controls server-side. e.g.) If Page.IsPostBack Then ' on submit - check for value Debug.Write ph.Controls.Count ' <-- this is 0 Debug.Write Request.Form("test") ' <-- this is ok - it finds it (?) Else Dim txt As TextBox = New WebControls.TextBox() txt.ID = "test" txt.Text = "test" ' add to placeholder on form ph.Controls.Add(txt) End If Why can't I see the controls added to the PlaceHolder control? Is there a way to set the runat="server" for these added controls to force them to post back? Thanks! You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.