Setting properties for controls

I have an asp.net page that I want to set all of the dropdownlist  properties with a button click. I have the following code and this is the error I am getting.

Dim ctlControl As Control
        For Each ctlControl In Page.Controls
            If ctlControl Is Control.DropDownList Then
                ctlControl.Enabled = False
            End If
        Next

Here is the error:

Compiler Error Message: BC30456: 'DropDownList' is not a member of 'System.Web.UI.Control'.

I am not sure what I am doing wrong or if I am even going at it the right way.

Thanks
ryaposAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TorrwinCommented:
You could try:

Select Case ctlControl.GetType
     Case DropDownList
          <your code here>
End Select
0
TimCotteeHead of Software ServicesCommented:
Hi ryapos,

        Dim ctlControl As WebControl
        For Each ctlControl In Page.Controls
            If ctlControl.GetType Is GetType(DropDownList) Then
                ctlControl.Enabled = False
            End If
        Next

Tim Cottee
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ryaposAuthor Commented:
Hi Tim,

This is the error I get when I try it

 Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.WebControl'.
0
DBAduck - Ben MillerPrincipal ConsultantCommented:
You should be able to just change TimCottee's suggestion to use Control instead of WebControl

        Dim ctlControl As Control
        For Each ctlControl In Page.Controls
            If ctlControl.GetType Is GetType(DropDownList) Then
                ctlControl.Enabled = False
            End If
        Next

LiteralControls are just Controls and WebControls are those with a UI element.

Ben.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.