A Better way? Finding ASP.NET controls, finding their id
        Posted  
        
            by CSharp
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by CSharp
        
        
        
        Published on 2010-06-01T18:22:35Z
        Indexed on 
            2010/06/01
            18:53 UTC
        
        
        Read the original article
        Hit count: 271
        
I have a method that finds all the controls, iterates through them, determines if they are a textbox,drop down list, etc.. retrieves their ID name, and depending on the ID name it will set a boolean statement (thus I would know if that section of the form is complete, and will email to a certain group of people) unfortunetly this is done with too many if statements and was wondering if I could get some help making this more manageable
protected void getEmailGroup()
{
    Control[] allControls = FlattenHierachy(Page);
    foreach (Control control in allControls)
    {
        if (control.ID != null)
        {
            if (control is TextBox)
            {
                TextBox txt = control as TextBox;
                if (txt.Text != "")
                {
                    if (control.ID.StartsWith("GenInfo_"))
                    {
                        GenInfo = true;
                    }
                    if (control.ID.StartsWith("EmpInfo_"))
                    {
                        EmpInfo = true;
                    }
                }
            }
            if (control is DropDownList)
            {
                DropDownList lb = control as DropDownList;
                if (lb.SelectedIndex != -1)
                {
                    if (control.ID.StartsWith("GenInfo_"))
                    {
                        GenInfo = true;
                    }
                    if (control.ID.StartsWith("EmpInfo_"))
                    {
                        EmpInfo = true;
                    }
                }
            }
        }
    }
}      
© Stack Overflow or respective owner