I get a compile error Type “ctltype” is not defined with this code.
This is .NET 1.1 legacy code so not good I know.
Anyone know why??
Public Function GetControlText(ByVal ctls As Control, ByVal ctlname As String, ByVal ctltype As Type) As String
Dim ctl As Control
Dim res As String
ctl = ctls.FindControl(ctlname)
If ctl Is Nothing Then
Return ""
End If
res = CType(ctl, ctltype).Text
If res Is Nothing Then
Return ""
Else
Return res
End If
End Function
The second operand for
CTypehas to be a type name – not a variable which is of typeType. In other words, the type has to be known at compile time.In this case, all you want is the
Textproperty – and you can get this with reflection: