How to identify what type a control is

Posted on 2004-10-17
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
  • 2

Accepted Solution

ryerras earned 125 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hey Audio! 9 44
InputLanguage 1 33
Expression Evaluater 3 38
"Emulate" TAB key when press Enter Key 3 47
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

860 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