egdotnet Posted June 7, 2004 Posted June 7, 2004 (edited) when I use a loop: For each mycontrol in panel1.controls if typeof(mycontrol) is textbox then dim mytextbox as textbox = mycontrol label1.text = "dog" elseif typeof(mycontrol) is label) then dim mylabel as label = mycontrol label1.text = "cat" End If Next It only works for controls added in design view rather than those previously added programatically. Why is that & how do I change it? Thanks Edited June 7, 2004 by egdotnet Quote
bob01900 Posted June 8, 2004 Posted June 8, 2004 previously added programatically Where did you add those controls to? Your code only loops through the controls that panel1 contains. So if a control is added to the page/form's control collection, you won't be able to find it. Also if a control inside panel1's control collection is a container, your loop does not go through the control collection of that container as well. For example, lets say if panel1 contains a PlaceHolder control called placeholder1, and placeholder1 contains textbox1. Your loop will find placeholder1, but NOT textbox1. Not sure if this helps. Quote
egdotnet Posted June 8, 2004 Author Posted June 8, 2004 Where did you add those controls to? Your code only loops through the controls that panel1 contains. So if a control is added to the page/form's control collection, you won't be able to find it. Also if a control inside panel1's control collection is a container, your loop does not go through the control collection of that container as well. For example, lets say if panel1 contains a PlaceHolder control called placeholder1, and placeholder1 contains textbox1. Your loop will find placeholder1, but NOT textbox1. Not sure if this helps. thanks -- they were in a panel inside, but when i took it out, it didn't make a difference. Quote
bob01900 Posted June 8, 2004 Posted June 8, 2004 Try this then, add the following just before the loop: Dim ctrl As Control ' Change textbox1 to the ID of the control that you are looking for ctrl = Me.FindControl("textbox1") ' Change to debug or trace if you are using them If Not ctrl Is Nothing Then Response.Write(ctrl.Parent.ID.ToString()) Else Response.Write("No controls found") End If This should show you where the control is, or if they are created at all. Hope this helps. Quote
*Experts* Bucky Posted June 8, 2004 *Experts* Posted June 8, 2004 Where is this code in relation to the code that dynamically adds controls to the page? So, when the page loads, is the control-creation code executed before this code? Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.