I get an error when trying to use the 'Name' function in the Control class in vb.net (as a code-behind to a APS.net form)
I want to be able to pull data from 6 text boxes with identical names (other than a number at the end) in a for loop
here is the error:
'Name' is not a member of 'System.Web.UI.Control'.
'Text' is not a member of 'System.Web.UI.Control'.
here is the 开发者_开发问答code:
For i As Integer = 0 To 5
For Each c As Control In Controls
If c.Name = "txtBox" & i Then
intValue(i) = Convert.ToInt32(c.Text)
End If
Next
Next i
Name is not in fact a member of System.Web.UI.Control. You probably have an instance of a derived class, in which case you will need to cast to the correct class before calling Name or Text.
With more context, we could give a better answer.
Try
For i As Integer = 0 To 5
For Each c As TextBox In Controls.OfType(of TextBox)()
If c.Name = "txtBox" & i Then
intValue(i) = Convert.ToInt32(c.Text)
End If
Next
Next i
精彩评论