Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


How to identify what type a control is

Posted on 2004-10-17
Medium Priority
Last Modified: 2011-09-20
In the following piece of program, how could I identify which are combo boxes, for example?

foreach (Control ctl in Controls)
   if ( ***a combo box is found*** )
      ctl.Text = "";
Question by:Alberto071397
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

ryerras earned 500 total points
ID: 12334724
ctl is DropDownList

Expert Comment

ID: 12334757
But the code you posted takes you no where. By default, the Page.Controls has the WebForm as one control. It wouldnt be able to find controls on the WebForm. For that you need to loop inside, try as follows
foreach (Control ctl in Controls)
      if(ctl is DropDownList)
             Response.Write("Text : "+ ctl.Text);
      else if (ctl.HasControls())
            foreach (Control ctl in ctrl.Controls)
                if(ctl is DropDownList)
                   Response.Write("Text: "+ ctl.Text);

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question