Solved

How to identify what type a control is

Posted on 2004-10-17
2
218 Views
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 = "";
}
0
Comment
Question by:Alberto071397
  • 2
2 Comments
 
LVL 6

Accepted Solution

by:
ryerras earned 125 total points
Comment Utility
ctl is DropDownList
0
 
LVL 6

Expert Comment

by:ryerras
Comment Utility
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);
            }
          }
}
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now