miyahira
asked on
Setting properties of aspx controls based in a generic List
I get a generic list of all controls in an aspx page. What I'm trying to do with each element of that list is to set a value for properties Visible and Enabled of those aspx controls.
I don't know how to get TYPE from each element of generic list.
I don't know how to get TYPE from each element of generic list.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim controlList As New List(Of Control)
controlList = AddControls(Page.Controls, controlList)
For Each ctl As Control In controlList
Response.Write(ctl.ID & "<br/>")
'Here I setup property Enabled of control textbox1
CType(Me.FindControl("textbox1"), TextBox).Enabled = True
'I'd like to setup property Enabled of control ctl.ID, but how to invoke <type of ctl>
CType(Me.FindControl(ctl.ID), <type of ctl> ).Enabled = True
Next
End Sub
Private Function AddControls(ByVal page As ControlCollection, ByVal controlList As List(Of Control)) As List(Of Control)
For Each c As Control In page
If c.ID IsNot Nothing Then
controlList.Add(c)
End If
If c.HasControls() Then
AddControls(c.Controls, controlList)
End If
Next
Return controlList
End Function
ASKER
I tried what you suggest, but got error
Type 'ctl.GetType' is undefined.
I even tried:
But got error: Type 'obj' is undefined.
Type 'ctl.GetType' is undefined.
I even tried:
For Each ctl As Control In controlList
Response.Write(ctl.ID & "<br/>")
Dim obj As Type = ctl.GetType()
CType(Me.FindControl(ctl.ID), obj).Enabled = False
Next
But got error: Type 'obj' is undefined.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Found solution by myself
CType(Me.FindControl(ctl.I
with:
CType(Me.FindControl(ctl.I