Solved

How to identify what type a control is

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 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