Results 1 to 5 of 5

Thread: Looping through controls

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Looping through controls

    How can I loop through controls on a form and find out what type they are.
    I want to loop through controls on a webform and if they are visible textboxes change there value if NULL to "na".

    Also

    If I placed this code in a module or class how would the code know which page I was refering to.

    Parksie

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    just a quick sample...this is in C#.
    VB Code:
    1. foreach(x in base.Controls)
    2.    if(x is Textbox)
    3.    {
    4.       //do something
    5.    }
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    The problem Im having is that I cant get to the text property of the control so I can change it.

    Parksie

  4. #4
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Originally posted by Memnoch1207
    just a quick sample...this is in C#.
    VB Code:
    1. foreach(x in base.Controls)
    2.    if(x is Textbox)
    3.    {
    4.       //do something
    5.    }
    actually ur code is wrong as the base class will not have any control in it

    you have to loop thru all class controls..do it the following way:
    VB Code:
    1. public sub SetTextBoxes(ByRef WebPage pageRef)
    2. for each ctrl as Control in pageRef.Controls)
    3. 'code (sorry i dont have vb.net here so i can say but try
    4. 'if (ctrl.gettype() = typeof("TextBox"))
    5. '(CType(ctrl, TextBox)).Text = "na"
    6. next
    7. end function
    anyways as i am no vb.net developer i might have some sintax errors
    Last edited by PT Exorcist; Oct 10th, 2003 at 03:40 PM.
    \m/\m/

  5. #5
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142
    Well, I'm not sure if this is what you need, but it might help a little.

    VB Code:
    1. Dim ctrl As Control
    2.         For Each ctrl In Me.Controls
    3.             If TypeOf ctrl Is TextBox Then
    4.                 If ctrl.visible = True Then
    5.                    If ctrl.Text = Nothing Then
    6.                        ctrl.text = "na"
    7.                    End If
    8.                 End If
    9.             End If
    10.         Next
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width