Using Variable for Text Box Name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In vb.net I'm trying to loop through textboxes using variables. If I try the
following, I receive the error "Value of type string cannot be converted to
System.Windows.Forms.Textbox

dim theTextBox as textbox
dim strName as string
dim i as integer
strname = "txtclorderfield" & i & ".text"
thetextbox = strname < this is where the syntax error appears
 
I still can't access the text that is in the text box. I receive the
following error:Object reference not set to an instance of an object. Here's
what I have for code. The error occurs on the strvalue =

Thanx,
Mike

Dim i As Integer
Dim strValue As String
Dim strTextBox As String
strValue = FindControl("txtclorderfield" & (i + 1) & ".text", Me).ToString

Private Function FindControl(ByVal ControlName As String, ByVal
CurrentControl As Control) As Control
For Each ctr As Control In CurrentControl.Controls
If ctr.Name = ControlName Then
Return ctr
Else
ctr = FindControl(ControlName, ctr)
If Not ctr Is Nothing Then
Return ctr
End If
End If
Next
End Function
 
Shouldn't this...

strValue = FindControl("txtclorderfield" & (i + 1) & ".text", Me).ToString

be...

strValue = FindControl("txtclorderfield" & (i + 1), Me).Text
 
I receive this error when trying that:
Object reference not set to an instance of an object.

Does it matter that I'm doing this from within a tab control?
 
Back
Top