Session("Controls") = Cntrl
In your loop, you're assigning a
single control to the session variable. On each iteration, you overwrite the variable with a different control. Since
System.Web.UI.Control
doesn't implement
IEnumerable
, you can't use it in a
For Each
loop.
To make the
For Each
loop work, you would need to add the controls to a
List(Of Control)
, and then store that list in the session variable.
However, storing controls in the session is a very bad idea. An instance of a control can only belong to a single control tree; you can't re-use it across different pages or different requests. Perhaps if you explain what you're trying to do, someone will be able to suggest a better approach.