Solved

control name as text

Posted on 2004-10-10
3
194 Views
Last Modified: 2010-04-23
i know this is farily easy, but i dont know what to search for

im wanting to control a bunch of different controls, and i dont want to use a control array...what i want to do is pass the text which will be the name

so something along the lines of

"text1".Text

thanks

~b
0
Comment
Question by:bramsquad
  • 2
3 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 125 total points
ID: 12273004
You can use something like this:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim objTB As TextBox

        objTB = FindControl("TextBox1")
        If Not (objTB Is Nothing) Then
            objTB.Text = "Surpise!"
        Else
            MessageBox.Show("Control not found!")
        End If
    End Sub

    Function FindControl(ByVal pName As String) As Control
        For Each x As Control In Me.Controls
            If x.Name.ToUpper = pName.ToUpper Then
                Return x
            End If
        Next
    End Function
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12273013
Maybe this way,

Dim oControl As Control
   For Each oControl In Me.Controls
     If oControl.Name = "TextBox1" Then
        Exit For
     End If
Next

' oControl is the control that you searching
MsgBox(oControl.Text)
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12273028
Sorry, That was concurrency :D
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now