Solved

How to identify what type a control is

Posted on 2004-10-17
2
232 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
ID: 12334724
ctl is DropDownList
0
 
LVL 6

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

15 Experts available now in Live!

Get 1:1 Help Now