mpdillon
Member
I am adding dynamic controls to my web page. I need to loop through them to determine the values entered by the user. What is the correct code to loop through all the controls on a web page. Here is what I have been trying and I will explain why the results are not what I want.
Dim ctl as Control
For Each ctl In XXXXXXX
If ctl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox") Then
‘Do Something
End If
Next
When XXXXXXX is Me.Controls I get values such as System.Web.Ui.LiteralControls, System.Web.UI.HtmlControls.HtlmHead or System.Web.UI.HtmlControls|Form.
When XXXXXXX is Me.form1.Controls I do not get any controls.
The For Each loop never finds a text box. Am I using the incorrect item for XXXXXXX or is the whole concept wrong?
For simplicity of testing, I did not add any dynamic controls but did place a text box and a button on the form. I placed the above code in the unload event.
Thank you.
Dim ctl as Control
For Each ctl In XXXXXXX
If ctl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox") Then
‘Do Something
End If
Next
When XXXXXXX is Me.Controls I get values such as System.Web.Ui.LiteralControls, System.Web.UI.HtmlControls.HtlmHead or System.Web.UI.HtmlControls|Form.
When XXXXXXX is Me.form1.Controls I do not get any controls.
The For Each loop never finds a text box. Am I using the incorrect item for XXXXXXX or is the whole concept wrong?
For simplicity of testing, I did not add any dynamic controls but did place a text box and a button on the form. I placed the above code in the unload event.
Thank you.