ASP.Net

M

Mark A. Sam

Hello,

I can't seem to get help in the VStudio and DotNet boards, so I thought I
would post my question here. Sorry for the out of context question, but I
am trying things usine Visual Web Developer 2005, and want to find out it
capabilities.

This code follows a procuedure to add values to textboxes on an Access form
by iterating through the controls collection:
Protected Sub Post_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Post.Click
Dim ctl As TextBox
Dim i As Integer

For Each ctl In Me.Controls
ctl.Text = i + 1
Next

End Sub

I get this error:
Exception Details: System.InvalidCastException: Unable to cast object of
type 'System.Web.UI.LiteralControl' to type
'System.Web.UI.WebControls.TextBox'.

Referring to this line:
Line 8: For Each ctl In Me.Controls

Does anyone know if I can iterate through the controls collection like in
VBA and how?

Thank you and God Bless,

Mark A. Sam
 
Top