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

Discussion in 'ASP .Net' started by crjunk, Sep 2, 2004.

  1. crjunk

    crjunk Guest

    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
    crjunk, Sep 2, 2004
    #1
    1. Advertising

  2. crjunk

    Karl Guest

    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

    "crjunk" <> wrote in message
    news:...
    > 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
    Karl, Sep 2, 2004
    #2
    1. Advertising

  3. crjunk

    crjunk Guest

    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


    "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:<u#>...
    > 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
    >
    > "crjunk" <> wrote in message
    > news:...
    > > 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
    crjunk, Sep 3, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rajesh Tiwari

    Can we use a usercontrol inside a usercontrol

    Rajesh Tiwari, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    409
    Rajesh Tiwari
    Aug 12, 2003
  2. nail
    Replies:
    0
    Views:
    1,539
  3. Fabiano
    Replies:
    2
    Views:
    597
    =?Utf-8?B?c3Jpbmk=?=
    Jun 3, 2005
  4. Spartaco

    usercontrol inside usercontrol

    Spartaco, Jul 31, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    600
    Spartaco
    Jul 31, 2007
  5. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    180
Loading...

Share This Page