Results 1 to 4 of 4

Thread: [2005] trying to loop through text boxes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Austin
    Posts
    397

    [2005] trying to loop through text boxes

    for some reason my code won't recognize text boxes on my webform?

    Code:
                        Dim myControl As Control
                        For Each myControl In Page.Controls
                            If myControl.GetType Is GetType(System.Web.UI.WebControls.TextBox) Then
                                CType(myControl, TextBox).Text = String.Empty
                            End If
                        Next myControl

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: [2005] trying to loop through text boxes

    Your boxes are probably not direct descendants of the Page object.

    You need to write a recursive function that calls itself each time on all controls as it finds them, so that all controls get analyzed.

    Be warned; your code is going to be slow. This is not the way to be clearing out boxes usually. Even though it means more work to you as the programmer, you should manually create an array with the Controls as each member of the array and then loop the array.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] trying to loop through text boxes

    Are you sure they're textboxes, or HTMLTEXTBOXes?

  4. #4
    Fanatic Member Valleysboy1978's Avatar
    Join Date
    Nov 2004
    Location
    Planet Xeoroaniar CC Posts:1,928,453,459,361
    Posts
    770

    Re: [2005] trying to loop through text boxes

    For a start Texas that will slow your page down immensely.
    I'm not sure it's the best way but I usually create a Sub called ClearTextBoxes() which I call and clears all the boxes. That way it can be called from anywhere and if I add any textboxes in the future I only have to add the .Clear() code in that Sub
    Life is one big rock tune

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