Using "For Each ctrl In.." Statment Inside UserControl

  • Thread starter Thread starter crjunk
  • Start date Start date
C

crjunk

I have a droped a UserControl named "ReceivedRecord1" onto my web
form. Currently, I have been saving information typed in by the user
with the following code that is located in the CodeBehind page of my
Web Form.

For Each ctrl In Page.FindControl("ReceivedRecord1").Controls
If TypeOf (ctrl) Is TextBox Then
' yada yada yada
End If
Next

I have now moved this code from my web from the CodeBehind page to the
UserControl CodeBehind page. Once I moved the code over to the
UserControl, I changed the for statement to the following:

For Each ctrl In Me.Controls
If TypeOf (ctrl) Is TextBox Then
' yada yada yada
End If
Next

This new code seems to not be able to find the TextBoxes that are on
the UserControl. What do I need to replace the "Me.Controls" with in
order for the code to find TextBoxes inside the UserControl?

Thanks!
crjunk
 
There's nothing wrong with what you've shown us. Are these textboxes being
added dynamically? Can you provide more sample code of what you're aspx
page looks for the page and the usercontrol (along with any relevant
codebehind)?

Karl
 
Hi Karl,

It finally started working. I didn't change any of the code. I'm not
exactly sure what happened to it but it is working now.

Thanks,
Crjunk
 
Back
Top