Hello - I am new at this posting bit. :)
I am trying to Load a user control at runtime - no problem to do this as ....
Dim analystView As AnalysisView = CType(Page.LoadControl("..\..\UserControls\Analysi sView.ascx"), AnalysisView)
The problem is that I am trying to dynamically determine what user control to load - we have several that might be loaded. Rather than coding a lot of conditional logic I am trying to convert the user control to the dynamic type using reflection.
This is my latest attempt, but it gives me a compile error:
Dim moduleArray() As [Module]
Dim ctrlType As Type
Dim myModule As [Module] = moduleArray(0)
ctrlType = myModule.GetType(ctrlClassName)
ctrl = CType(Page.LoadControl(ctrlLocation), ctrlType)
The compile error is: Type 'ctrlType' is not defined - for the red ctrlType reference above.
I've run the reflection code by commenting out the conversion and I am successfully finding the right class in the module so the problem does not lie with the reflection - but with the conversion (of course since it won't even compile that way. )
I guess
VB does not like me using CType with a variable for the Type parameter - does anyone know how I can cast the UserControl to a variable value at run time?
Thanks!!
dpinkerton