c# - How to get the "typeof" of a custom user control -


i have custom user control datepicker.cs. inside of piece of code have collection of controls checking type of control , doing logic based on type. problem following:

typeof(datepicker) 

evalutes to:

{name = "datepicker" fullname = "cusitecore.cedarsc.usercontrols.datepicker"} 

but when run debugger , @ type of control on web form is:

{name = "cedarsc_usercontrols_datepicker_ascx" fullname = "asp.cedarsc_usercontrols_datepicker_ascx"} 

these 2 things aren't equal correct logic isn't getting evaluated. i've tried using type.gettype("asp.cedarsc_usercontrols_datepicker_ascx") returns null.

edit

here's i'm trying do:

private readonly dictionary<type, controltype?> _controltypes = new dictionary<type, controltype?>     {         {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 on children     if (control.controls.count > 0 && controltype == null) // don't want recurse children of controls 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 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 listcontrol;                 if (listcontrol != null)                     _fields.addfieldvalue(listcontrol.id, string.join(", ", listcontrol.items.cast<listitem>().where(item => item.selected).select(item => item.value).toarray()));                 break;             case controltype.dropdownlist:                 dropdownlist dropdownlist = control dropdownlist;                 if (dropdownlist != null)                     _fields.addfieldvalue(dropdownlist.id, dropdownlist.selectedvalue);                 break;             case controltype.hiddenfield:                 hiddenfield hiddenfield = control hiddenfield;                 if (hiddenfield != null)                     _fields.addfieldvalue(hiddenfield.id, hiddenfield.value);                 break;             case controltype.textbox:                 textbox textbox = control textbox;                 if (textbox != null)                     _fields.addfieldvalue(textbox.id, textbox.text);                 break;             case controltype.datepicker:                 datepicker datepicker = control datepicker;                 if (datepicker != null)                     _fields.addfieldvalue(datepicker.id, datepicker.text);                 break;             case controltype.customselect:                 customselect customselect = control customselect;                 if(customselect != null)                     _fields.addfieldvalue(customselect.id, customselect.selectedvalue);                 break;             case controltype.label:                 label label = control label;                 if(label != null)                     _fields.addfieldlabel(label.associatedcontrolid, label.text);                 break;             default:                 throw new exception("unhandled control");         }     } } 

asp.net creates it's own type inherited user controls.

for comparisons use is operator.
extractions use control.gettype().basetype.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -