title: How to get the "typeof" of a custom user control
body: <p>I have a custom user control DatePicker.cs. Inside of another piece of code I have a collection of controls where I am checking the type of the control and doing some logic based on the type. My problem is the following:</p>
  
  <pre><code>typeof(DatePicker)
  </code></pre>
  
  <p>Evalutes to:</p>
  
  <pre><code>{Name = "DatePicker" FullName = "cusitecore.cedarsc.UserControls.DatePicker"}
  </code></pre>
  
  <p>But when I run the debugger and look at the type of the control that is on my web form it is:</p>
  
  <pre><code>{Name = "cedarsc_usercontrols_datepicker_ascx" FullName = "ASP.cedarsc_usercontrols_datepicker_ascx"}
  </code></pre>
  
  <p>These two things aren't equal so the correct logic isn't getting evaluated. I've tried using Type.GetType("ASP.cedarsc_usercontrols_datepicker_ascx") but this returns null.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here's what I'm trying to do:</p>
  
  <pre><code>private readonly Dictionary&lt;Type, ControlType?&gt; _controlTypes = new Dictionary&lt;Type, ControlType?&gt;
      {
          {typeof(CheckBox), ControlType.CheckBox},
          {typeof(CheckBoxList), ControlType.CheckBoxList},
          {typeof(DropDownList), ControlType.DropDownList},
          {typeof(HiddenField), ControlType.HiddenField},
          {typeof(ListBox), ControlType.ListBox},
          {typeof(RadioButton), ControlType.RadioButton},
          {typeof(RadioButtonList), ControlType.RadioButtonList},
          {typeof(TextBox), ControlType.TextBox},
          {typeof(Label), ControlType.Label},
          {typeof(DatePicker), ControlType.DatePicker},
          {typeof(CustomSelect), ControlType.CustomSelect}
      };
  
  private void PopulateFields(Control control)
  {
      ControlType? controlType;
      _controlTypes.TryGetValue(control.GetType(), out controlType);
  
      // recurse over the children
      if (control.Controls.Count &gt; 0 &amp;&amp; controlType == null) // don't want to recurse into children of controls we are reading values of
      {
          foreach(Control childControl in control.Controls)
          {
              PopulateFields(childControl);
          }
      }
  
      if (controlType != null)
      {
          switch (controlType)
          {
              case ControlType.CheckBox:
              case ControlType.RadioButton:
                  CheckBox checkBox = control as CheckBox;
                      if (checkBox != null)
                          _fields.AddFieldValue(checkBox.ID, checkBox.Checked ? "Checked" : "Not Checked");
                      break;
              case ControlType.CheckBoxList:
              case ControlType.ListBox:
              case ControlType.RadioButtonList:
                  ListControl listControl = control as ListControl;
                  if (listControl != null)
                      _fields.AddFieldValue(listControl.ID, String.Join(", ", listControl.Items.Cast&lt;ListItem&gt;().Where(item =&gt; item.Selected).Select(item =&gt; item.Value).ToArray()));
                  break;
              case ControlType.DropDownList:
                  DropDownList dropDownList = control as DropDownList;
                  if (dropDownList != null)
                      _fields.AddFieldValue(dropDownList.ID, dropDownList.SelectedValue);
                  break;
              case ControlType.HiddenField:
                  HiddenField hiddenField = control as HiddenField;
                  if (hiddenField != null)
                      _fields.AddFieldValue(hiddenField.ID, hiddenField.Value);
                  break;
              case ControlType.TextBox:
                  TextBox textBox = control as TextBox;
                  if (textBox != null)
                      _fields.AddFieldValue(textBox.ID, textBox.Text);
                  break;
              case ControlType.DatePicker:
                  DatePicker datePicker = control as DatePicker;
                  if (datePicker != null)
                      _fields.AddFieldValue(datePicker.ID, datePicker.Text);
                  break;
              case ControlType.CustomSelect:
                  CustomSelect customSelect = control as CustomSelect;
                  if(customSelect != null)
                      _fields.AddFieldValue(customSelect.ID, customSelect.SelectedValue);
                  break;
              case ControlType.Label:
                  Label label = control as Label;
                  if(label != null)
                      _fields.AddFieldLabel(label.AssociatedControlID, label.Text);
                  break;
              default:
                  throw new Exception("Unhandled Control");
          }
      }
  }
  </code></pre>