troubleshooting Question

Setting properties of aspx controls based in a generic List

Avatar of miyahira
miyahiraFlag for Peru asked on
ASP.NET
4 Comments1 Solution244 ViewsLast Modified:
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.

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

Open in new window

ASKER CERTIFIED SOLUTION
miyahira

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros