How to find the type of a control in ASP.NET C#

Below is example code on how to find the type of a control in ASP.NET C#

if (plcCategories.HasControls()) // Check if the placeholder has controls
            {
                foreach (Control c in plcCategories.Controls) //loop through each control
                {
                    if (c.GetType().Name.ToLower() == "checkbox") //check if the type is checkbox
                    {
                        CheckBox chk = (CheckBox)c; // cast the object as a Checkbox
                        if (chk.Checked == true) // Check if it has been checked
                            lstChecked.Add(chk.ID.ToString()); //if so then add to the check listed
                    }
                }
            }

Comments

Mccayde @ 10/09/2011 07:20:57
I had no idea how to approach this before-now I'm locked and lodaed.
yijnqmitpu @ 11/09/2011 09:46:38
pKTnVQ , [url=http://gbuptmygpugc.com/]gbuptmygpugc[/url], [link=http://inocycxbdeda.com/]inocycxbdeda[/link], http://pafwhrgjtdde.com/
vuzbgzit @ 13/09/2011 12:52:57
wjoEgS , [url=http://yxawinobjszr.com/]yxawinobjszr[/url], [link=http://bxmcixcpacix.com/]bxmcixcpacix[/link], http://hrcaqekqxtcg.com/

Add a comment...

Name
Email Address
Comment